Trium918 Posted March 26, 2007 Share Posted March 26, 2007 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 More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 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. Link to comment https://forums.phpfreaks.com/topic/44415-problems-with-logging-in/#findComment-215679 Share on other sites More sharing options...
Trium918 Posted March 26, 2007 Author Share Posted March 26, 2007 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; } Link to comment https://forums.phpfreaks.com/topic/44415-problems-with-logging-in/#findComment-215683 Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 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; } Link to comment https://forums.phpfreaks.com/topic/44415-problems-with-logging-in/#findComment-215686 Share on other sites More sharing options...
Trium918 Posted March 26, 2007 Author Share Posted March 26, 2007 frost110 I'm not getting the password. This is the Mysql command insert into writers (username, password, full_name) values ('tom','test', 'Robert Bobbins'); Link to comment https://forums.phpfreaks.com/topic/44415-problems-with-logging-in/#findComment-215690 Share on other sites More sharing options...
Trium918 Posted March 26, 2007 Author Share Posted March 26, 2007 Were are the webmasters? I need your help. Link to comment https://forums.phpfreaks.com/topic/44415-problems-with-logging-in/#findComment-215710 Share on other sites More sharing options...
Trium918 Posted March 26, 2007 Author Share Posted March 26, 2007 I entered "test" into the username form and I got the print "The password you entered is incorrect"; This means that both variables have no value. Could someone explain to me why there is no data being pulled from the database? Link to comment https://forums.phpfreaks.com/topic/44415-problems-with-logging-in/#findComment-215720 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.