Trekky1700 Posted May 10, 2010 Share Posted May 10, 2010 Hi everyone, I'm having a problem with part of a login code. When I try to login, rather than redirecting to the index page like it's told, it just stays on the blank "login.php" file. Could some nice person tell me what I'm doing wrong? <?php session_start(); session_regenerate_id (); include ("dbconnect.php"); $user=$_POST['user']; $pass=$_POST['pass']; $title=$_POST['title']; if(isset($user) && isset($pass)) { if (isset($_SESSION["logged_in_".$title]) && $_SESSION["logged_in_".$title] == $user) { echo $user.", you are already logged in.<BR><BR>"; exit; } $connection = new db(); $connection->connect(); $result = mysql_query("SELECT username,password FROM mobagi_".$title." WHERE username='".$user."' AND password=sha1('".$pass."') "); if(!$result) { echo "An error occured while querying database"; exit; } if(mysql_num_rows($result)>0) { $_SESSION["logged_in_".$title]=$user; session_register("logged_in_".$title); header("Location:index.php"); } else { header("Location:index.php"); } $connection->close(); } else if ($user || $pass) { echo "Please fill in both fields."; } ?> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/ Share on other sites More sharing options...
Joshua4550 Posted May 10, 2010 Share Posted May 10, 2010 Try: header("Location: /index.php"); Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055597 Share on other sites More sharing options...
Trekky1700 Posted May 10, 2010 Author Share Posted May 10, 2010 I tried it, it still didn't work. Does anyone know of any pre-built systems/tutorials that are good? Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055601 Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 Don't use session_register. The PHP manual says: This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. Just doing <?php $_SESSION["logged_in_".$title]=$user; ?> is fine. As for your problem, try changing: <?php $result = mysql_query("SELECT username,password FROM mobagi_".$title." WHERE username='".$user."' AND password=sha1('".$pass."') "); if(!$result) { echo "An error occured while querying database"; exit; } ?> to <?php $query = "SELECT username,password FROM mobagi_".$title." WHERE username='".$user."' AND password=sha1('".$pass."') "; $result = mysql_query($query) or die("An error occured while querying database, query: $query<br>" . mysql_error()); ?> and see if an error gets issued. Ken Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055612 Share on other sites More sharing options...
Trekky1700 Posted May 10, 2010 Author Share Posted May 10, 2010 No error was issued, it just keeps going to a blank screen (the login.php file). It does the same if I enter the wrong password too. Is there any other code I should include, such as the login box code or the database info? Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055614 Share on other sites More sharing options...
Trekky1700 Posted May 10, 2010 Author Share Posted May 10, 2010 Ok, apperently none of the scripts on the page are running. I just tried filling out 1 out of the 2 boxes on my login, and it still displays blank. Here's my current code. <?php session_start(); session_regenerate_id (); include ("dbconnect.php"); $user=$_POST['username']; $pass=$_POST['password']; $title=$_POST['accounttype']; if(isset($user) && isset($pass)) { if (isset($_SESSION["logged_in_".$title]) && $_SESSION["logged_in_".$title] == $user) { echo $user.", you are already logged in.<BR><BR>"; exit; } $connection = new db(); $connection->connect(); $query = "SELECT username,password FROM ".$title." WHERE username='".$user."' AND password=sha1('".$pass."') "; $result = mysql_query($query) or die("An error occured while querying database, query: $query<br>" . mysql_error()); if(mysql_num_rows($result)>0) { $_SESSION["logged_in_".$title]=$user; header("Location:index.php"); } else { header("Location:register.php"); } $connection->close(); } else if ($user || $pass) { echo "Please fill in both fields."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055620 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2010 Share Posted May 10, 2010 Are you debugging this code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that ALL the errors php detects will be reported and displayed? Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055623 Share on other sites More sharing options...
Trekky1700 Posted May 10, 2010 Author Share Posted May 10, 2010 Are you debugging this code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that ALL the errors php detects will be reported and displayed? Current Error Settings: ; display_errors ; Default Value: On ; Development Value: On ; Production Value: Off ; display_startup_errors ; Default Value: On ; Development Value: On ; Production Value: Off ; error_reporting ; Default Value: E_ALL & ~E_NOTICE ; Development Value: E_ALL | E_STRICT ; Production Value: E_ALL & ~E_DEPRECATED ; html_errors ; Default Value: On ; Development Value: On ; Production value: Off ; log_errors ; Default Value: On ; Development Value: On ; Production Value: On Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055624 Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 Those are all comments and don't tell use the current settings on your system. Ken Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055627 Share on other sites More sharing options...
Trekky1700 Posted May 10, 2010 Author Share Posted May 10, 2010 Those are all comments and don't tell use the current settings on your system. Ken Thanks everyone for the help, ended up going through every scrap of code I had written prior, and it turened out to be a tiny spelling difference in another file associated to the login process. Sorry for wasting anyones time! Quote Link to comment https://forums.phpfreaks.com/topic/201206-php-login-system-not-working/#findComment-1055630 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.