cheesybiscuits Posted January 30, 2012 Share Posted January 30, 2012 Hi, I'm kinda new to php, so I followed a video tutorial on making a login/registration system and nearly everything works, except for when a registered user follows a link to the members.php page, the $_SESSION variable is supposed to check if they are logged-in and say "Welcome, [name of user]!. But it keeps saying I need to be logged in, even though I am. The php code from the members.php page. if ($_SESSION['username']) { echo "Welcome," .$_SESSION['username']. "!"; } else { die ("You must be logged in."); } This is the php code form the login page. session_start(); $username = $_POST['username']; $password = $_POST['password']; if ($username&&$password) { $connect = mysql_connect("localhost","root","password") or die ("Unable to connect"); mysql_select_db("database") or die ("Unable to find database"); $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrow = mysql_num_rows($query); if ($numrow!=0) { // while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; } if ($username==$dbusername&&md5($password)==$dbpassword) echo "You're in! - <a href=\"members.php\">Go to members page</a>"; $_SESSION['username'] == $dbusername; } else { echo "Incorrect password"; } } else { die ("That user doesn't exist"); } } else { die("Please enter a username and password"); } Any help would be much appreciated. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2012 Share Posted January 30, 2012 Do you have session_start(); at the head of the members.php script, before any output is sent to the browser? Quote Link to comment Share on other sites More sharing options...
cheesybiscuits Posted January 30, 2012 Author Share Posted January 30, 2012 I tried it, and it now sends the variable, but I get this message Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /srv/disk1/956153/www/lincscrusade.mywebcommunity.org/members.php:6) in /srv/disk1/956153/www/lincscrusade.mywebcommunity.org/members.php on line 7 Welcome,cheesybiscuits! Quote Link to comment Share on other sites More sharing options...
jotorres1 Posted January 30, 2012 Share Posted January 30, 2012 Try putting session_start() on line 1 Quote Link to comment Share on other sites More sharing options...
cheesybiscuits Posted January 30, 2012 Author Share Posted January 30, 2012 Thanks guys worked like a charm. 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.