ntroycondo Posted June 23, 2010 Share Posted June 23, 2010 My logon script is redirecting to the correct page without error but that page doesn't show the user logged on and echos "You Must be Logged In". Any thing look out of place? Redirected page: <?php session_start(); if ($_SESSION['username']) echo "Welcome, ".$_SESSION['username']."!"; else die("You must be logged in!"); ?> Logon.php script: <?php session_start(); $username = $_POST['user_name']; $password = $_POST['password']; $password = md5($password); if ($username&&$password) { $connect = mysql_connect("host", "root", "password") or die("Couldn't connect"); mysql_select_db("myDB") or die("Couldn't find DB"); $query = mysql_query("SELECT * FROMmyDB_users WHERE user_name='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['user_name']; $dbpassword = $row['password']; } if ($username==$dbusername&&$password==$dbpassword) { header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/"."member.php"); mysql_free_result ($result); // Free up the resources. ###exit(); ### echo "Welcome! <a href='member.php'>Click</a> here."; ###$_SESSION['username']=$username; } else echo "Incorrect password!"; } else die("User does not exist"); } else die("Please enter user name and password."); ?> Link to comment https://forums.phpfreaks.com/topic/205621-user-logon-session-failing/ Share on other sites More sharing options...
Ruzzas Posted June 23, 2010 Share Posted June 23, 2010 Don't you need { & }'s? Link to comment https://forums.phpfreaks.com/topic/205621-user-logon-session-failing/#findComment-1076006 Share on other sites More sharing options...
inversesoft123 Posted June 23, 2010 Share Posted June 23, 2010 Why are you not registering the session.? Do not pass this. ###exit(); ### echo "Welcome! <a href='member.php'>Click</a> here."; $_SESSION['username']=$username; // << register session here Link to comment https://forums.phpfreaks.com/topic/205621-user-logon-session-failing/#findComment-1076010 Share on other sites More sharing options...
Ruzzas Posted June 23, 2010 Share Posted June 23, 2010 Why are you not registering the session.? Do not pass this. ###exit(); ### echo "Welcome! <a href='member.php'>Click</a> here."; $_SESSION['username']=$username; // << register session here Good eye! Link to comment https://forums.phpfreaks.com/topic/205621-user-logon-session-failing/#findComment-1076012 Share on other sites More sharing options...
ntroycondo Posted June 23, 2010 Author Share Posted June 23, 2010 Thanks inversesoft123. Definitely didn't want to comment out that! Link to comment https://forums.phpfreaks.com/topic/205621-user-logon-session-failing/#findComment-1076260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.