SirChick Posted August 14, 2007 Share Posted August 14, 2007 I been trying to get my session to work from when the user logs in.. but for the life of me.. it won't load up data on other pages... i did a print of the session and it didn't pick up the User ID so im guessing its relating to the creation of the session on my login page which i have provided below. There's no reason to suggest that it shouldn't work so I'm kinda stuck. <? //when login is pushed run code // Start up the session session_start(); if (isset($_POST['Login'])) { //connect to database as par usual // Needed to move these lines above the mysql_real_escape() calls mysql_connect("localhost", "root", "Private") or die (mysql_error()); mysql_select_db("civilian") or die (mysql_error()); //set input from user into these variables $Username = mysql_real_escape_string($_POST['Username']); $Password = mysql_real_escape_string($_POST['Password']); //check if username exists $chkLogin = mysql_query("SELECT * FROM `userregistration` WHERE `Username` = '$Username' AND Password = '$Password'"); if (!($row = mysql_fetch_assoc($chkLogin))) { die('Username or password was incorrect. Please press the back button on your browser and try again!'); } // Store the currently logged in user $_SESSION['Current_User'] = $row['Userid']; header("Location: HomeLogin.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/ Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 Try this: <?php //when login is pushed run code // Start up the session session_start(); if (isset($_POST['Login'])) { //connect to database as par usual // Needed to move these lines above the mysql_real_escape() calls mysql_connect("localhost", "root", "Private") or die (mysql_error()); mysql_select_db("civilian") or die (mysql_error()); //set input from user into these variables $Username = mysql_real_escape_string($_POST['Username']); $Password = mysql_real_escape_string($_POST['Password']); //check if username exists $chkLogin = mysql_query("SELECT * FROM `userregistration` WHERE `Username` = '$Username' AND Password = '$Password'"); $row = mysql_fetch_assoc($chkLogin); if (!$row['Userid']) { die('Username or password was incorrect. Please press the back button on your browser and try again!'); } // Store the currently logged in user $_SESSION['Current_User'] = $row['Userid']; header("Location: HomeLogin.php"); } ?> Edit: ; Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/#findComment-323584 Share on other sites More sharing options...
SirChick Posted August 14, 2007 Author Share Posted August 14, 2007 Why did you change the query? Because that worked before, its the session creation itself thats going wrong. This occurs now: Username or password was incorrect. Please press the back button on your browser and try again! Even if the data is correct. Let me know thanks Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/#findComment-323594 Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 The query is exactly the same, I did not change it. Theoretically It should work, Unless you do not have a Userid field in your userregistration table. You do have that field, and it isn't Null(0)? Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/#findComment-323598 Share on other sites More sharing options...
SirChick Posted August 14, 2007 Author Share Posted August 14, 2007 UserID is the exact word and its not null. Is it case sensitive? Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/#findComment-323606 Share on other sites More sharing options...
tlavelle Posted August 14, 2007 Share Posted August 14, 2007 Make sure that the session.save_path variable in your php.ini file points to a valid temporary directory for your system. Also, try moving the session_start() above the comments Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/#findComment-323609 Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 UserID is the exact word and its not null. Is it case sensitive? Yes, It is case sensitive. Make sure that the session.save_path variable in your php.ini file points to a valid temporary directory for your system. Also, try moving the session_start() above the comments Comments does not get phrased by php. Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/#findComment-323611 Share on other sites More sharing options...
SirChick Posted August 14, 2007 Author Share Posted August 14, 2007 Oh wait i got it working ... damn it was the case sensitive issue lol! Something so little ! I should of spotted that to be honest. Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/#findComment-323621 Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 Look for the Topic Solved button. Quote Link to comment https://forums.phpfreaks.com/topic/64845-solved-session-still-isnt-working/#findComment-323628 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.