Jump to content

Problems with logging in


Trium918

Recommended Posts


This program comes straight out a book. There are no flaws or shouldn't be.

My thing is this, the author doesn't show the reader how to write code with

register_globals = Off . This has to be the problem because it works when

register_globals = On. I need help rewriting this code.

 

 

stories.php

<?php

include "include_fns.php";
session_register("auth_user");

if (!check_auth_user()) {
?>
<FORM ACTION="login.php" METHOD=POST>
<TABLE BORDER=0>
<TR>
  <TD>Username</TD>
  <TD><INPUT SIZE=16 NAME="username"></TD>
</TR>
<TR>
  <TD>Password</TD>
  <TD><INPUT SIZE=16 TYPE="PASSWORD" NAME="password"></TD>
</TR>
</TABLE>
<INPUT TYPE=SUBMIT VALUE="Log in">
</FORM>
<?php
}
else {
  $conn = db_connect();

  $w = get_writer_record($auth_user);

  print "Welcome, ".$w[full_name];
  print " (<A HREF=\"logout.php\">Logout</A>)";
  print "<p>";

  $sql = "select * from stories where writer = '$auth_user' ".
         "order by created desc";
  $result = mysql_query($sql, $conn);

  print "Your stories: ";
  print mysql_num_rows($result);
  print " (<A HREF=\"story.php\">Add new</A>)";
  print "<br><br>";
  
  if (mysql_num_rows($result)) {
    print "<TABLE>";
    print "<TR><TH>Headline</TH><TH>Page</TH>";
    print "<TH>Created</TH><TH>Last modified</TH></TR>";
    while ($qry = mysql_fetch_array($result)) {
      print "<TR>";
      print "<TD>";
      print $qry[headline];
      print "</TD>";
      print "<TD>";
      print $qry

;
      print "</TD>";
      print "<TD>";
      print date("M d, H:i", $qry[created]);
      print "</TD>";
      print "<TD>";
      print date("M d, H:i", $qry[modified]);
      print "</TD>";
      print "<TD>";
      if ($qry[published])
        print "[Published ".date("M d, H:i", $qry[published])."]";
      else {
        print "[<A HREF=\"story.php?story=".$qry[id]."\">edit</A>] ";
        print "[<A HREF=\"delete_story.php?story=".$qry[id]."\">delete</A>] ";
        print "[<A HREF=\"keywords.php?story=".$qry[id]."\">keywords</A>]";
      }
      print "</TD>";
      print "</TR>";
    }
    print "</TABLE>";
  }

}
?>

 

login.php

<?php

include "include_fns.php";

if ( (!$username) || (!$password) ) {
  print "You must enter your username and password to proceed";
  exit;
}

if (login($username, $password)) {
  $auth_user = $username;
  session_register("auth_user");
  header("Location: $HTTP_REFERER");
}
else {
  print "The password you entered is incorrect";
  exit;
}


?>

Link to comment
https://forums.phpfreaks.com/topic/44415-problems-with-logging-in/
Share on other sites

Lol this just proves that books are lame. Soo many unnecessary print statements sheesh!

 

register_globals off means that $_POST['username'] has to be called from $_POST['username'] and not $username.

 

Basically anywhere you are calling just $username etc. replace it with either $_POST['username']  $_GET['username'] or heck even $_REQUEST['username'] depending on if it was $_POST or $_GET data or if you don't care how it got there ($_REQUEST) and it should work.

Would it be more like this or do I have to do the same in the login() function?

$_POST['username'] works but I am getting the

print "The password you entered is incorrect"; error.

 

include "include_fns.php";

if ( (!$_POST['username']) || (!$_POST['password']) ) {
  print "You must enter your username and password to proceed";
  exit;
}

if (login($username, $password)) {
  $auth_user = $username;
  session_register("auth_user");
  header("Location: $HTTP_REFERER");
}
else {
  print "The password you entered is incorrect";
  exit;
}

include "include_fns.php";

$username = (isset($_POST['username']))?$_POST['username']:false;
$password = (isset($_POST['password']))?$_POST['password']:false;

if ( (!$username) || (!$password) ) {
  print "You must enter your username and password to proceed";
  exit;
}

if (login($username, $password)) {
  $auth_user = $username;
  session_register("auth_user");
  header("Location: $HTTP_REFERER");
}
else {
  print "The password you entered is incorrect";
  exit;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.