Custer Posted July 19, 2007 Share Posted July 19, 2007 Hehe, well, I'm back with a login script, and it's a rather simple one, but I keep getting a blank page, and I ran this code by one of my programming friends and he couldn't find anything wrong, so perhaps one of you guys can. <?PHP init_set('display_errors',1); error_reporting(E_ALL); //session start and connect session_start(); require ("configure.php"); mysql_connect ("$dbhost", "$dbuser", "$dbpass")or die("Could not connect: ".mysql_error()); mysql_select_db("$dbname") or die(mysql_error()); //grabs information $username = $_POST['username']; $password = md5($_POST['password']); $username = mysql_escape_string($username); $password = mysql_escape_string($password); //checks data $query = mysql_query("SELECT * FROM users WHERE username = '$username'"); $array = mysql_fetch_assoc($query); if ($array['username'] == $username) { $1= '1'; } else { echo "The username does not exist."; die(); } if ($array['password'] == $password) { $2= '1'; } else { echo "Your password is incorrect."; die(); } if ($array['userlevel'] == '1') { $level = 'user'; } elseif ($array['userlevel'] == '9') { $level = 'admin'; } else { echo "Please try again."; die(); } $_SESSION['username'] = $username; if($1 == '1' AND $2 == '1' AND $level == '1') { echo "Thank you for logging in : ".$username; header ('Location: /members.php');} elseif($1 == '1' AND $2 == '1' AND $level == '9') {header ('Location: /admin.php');} else { echo "Extreme Error."; die(); } ?> Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted July 19, 2007 Share Posted July 19, 2007 Hehe, well, I'm back with a login script, and it's a rather simple one, but I keep getting a blank page, and I ran this code by one of my programming friends and he couldn't find anything wrong, so perhaps one of you guys can. <?PHP init_set('display_errors',1); error_reporting(E_ALL); //session start and connect session_start(); require ("configure.php"); mysql_connect ("$dbhost", "$dbuser", "$dbpass")or die("Could not connect: ".mysql_error()); mysql_select_db("$dbname") or die(mysql_error()); //grabs information $username = $_POST['username']; $password = md5($_POST['password']); $username = mysql_escape_string($username); $username = mysql_escape_string($password); //checks data $query = mysql_query("SELECT * FROM users WHERE username = '$username'"); $array = mysql_fetch_assoc($query); if ($array['username'] == $username) { $1= '1'; } else { echo "The username does not exist."; die(); } if ($array['password'] == $password) { $2= '1'; } else { echo "Your password is incorrect."; die(); } if ($array['userlevel'] == '1') { $level = 'user'; } elseif ($array['userlevel'] == '9') { $level = 'admin'; } else { echo "Please try again."; die(); } $_SESSION['username'] = $username; if($1 == '1' AND $2 == '1' AND $level == '1') { echo "Thank you for logging in : ".$username; header ('Location: /members.php');} elseif($1 == '1' AND $2 == '1' AND $level == '9') {header ('Location: /admin.php');} else { echo "Extreme Error."; die(); } ?> haven't disseminated everything but your init_set at the top of the code should be "ini_set". also add... ini_set('display_startup_errors', 1); to make sure you catch everything, that should tell you the errors Quote Link to comment Share on other sites More sharing options...
Custer Posted July 19, 2007 Author Share Posted July 19, 2007 No luck, still am getting a blank page. :/ Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted July 19, 2007 Share Posted July 19, 2007 variable names cant start with a number also... Quote Link to comment Share on other sites More sharing options...
Custer Posted July 19, 2007 Author Share Posted July 19, 2007 Argh, silly me, yah, I was definitely in a rush when I was writing this, but let me try that. Quote Link to comment Share on other sites More sharing options...
Custer Posted July 19, 2007 Author Share Posted July 19, 2007 Okay, just retried it and got Extreme Error, which is weird, because I wrote it so that should never ever happen, because the username and password checks would put out their errors first... EDIT: Found the problem! On the $level == '1' in the final if statements, it's not 1 or 9, but user or admin. Quote Link to comment Share on other sites More sharing options...
Custer Posted July 19, 2007 Author Share Posted July 19, 2007 Sorry for the triple post... Okay, just tried it and got this error: Thank you for logging in : test Warning: Cannot modify header information - headers already sent by (output started at /www/newsit.es/c/u/s/custopoly/htdocs/login.php:49) in /www/newsit.es/c/u/s/custopoly/htdocs/login.php on line 50 Notice: Undefined index: log in /www/newsit.es/c/u/s/custopoly/htdocs/login.php on line 57 So my headers aren't working... Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted July 19, 2007 Share Posted July 19, 2007 you can use a different form of redirection or use ob_start(): http://us2.php.net/manual/en/function.ob-start.php Quote Link to comment Share on other sites More sharing options...
ryeman98 Posted July 19, 2007 Share Posted July 19, 2007 $_SESSION['username'] = $username; if($1 == '1' AND $2 == '1' AND $level == '1') { echo "Thank you for logging in : ".$username; header ('Location: /members.php');} Not too sure but, if they're going to be redirected to members.php, why do you echo "Thank you for logging in"? Quote Link to comment Share on other sites More sharing options...
Custer Posted July 19, 2007 Author Share Posted July 19, 2007 I'll look into the ob_start, Ben. Rye, I wanted it to say thanks like you always see on other sites and then redirect them, I guess, but I guess you're right that I don't need it too. Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted July 19, 2007 Share Posted July 19, 2007 rye, that wont work, you cant send header() by itself after any output has been printed to the screen because headers need to be generated before said output can't remember exactly what you need... but output buffering is the way to do it if you want to stick with header() after printing Quote Link to comment Share on other sites More sharing options...
Custer Posted July 19, 2007 Author Share Posted July 19, 2007 Okay, I just got rid of the echo line and the headers work fine. I guess that'll work for now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.