Hey I am working on a site (will be my biggest yet) I am having issues with sessions I have set up a basic session at the moment but I want to redirect the user to a certain page (based on ID ) and they can only access that page Similar to profile pages This is the login code <?php session_start (); $username = $_POST ['username']; $password = $_POST ['password']; if ($username&&$password) { $connect = mysql_connect ("localhost", "root" , "") or die ("didnt work cant connect"); mysql_select_db ("ireland") or die ("cant find db"); $query = mysql_query ("SELECT * FROM users WHERE username='$username'"); $numrows = mysql_num_rows ($query); if ($numrows!=0) { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&$password==$dbpassword) { header("Location: member.php"); $_SESSION ['username']=$dbusername; } else echo "incorrect password"; } else die ("user does not exist"); } else die ("please enter username and or password"); ?> PHP: and this is the session header <?php session_start (); if ($_SESSION['username']){ echo ""; } else header("Location: members1.php"); ?> PHP: any thoughts
In this part : if ($username==$dbusername&&$password==$dbpassword) { header("Location: member.php"); $_SESSION ['username']=$dbusername; } PHP: You set the location to member.php and then AFTER that you set the session variable to $dbusername... Try to set first the variable and then the redirect : if ($username==$dbusername&&$password==$dbpassword) { $_SESSION ['username']=$dbusername; header("Location: member.php"); } PHP: