Catfish Posted January 10, 2009 Share Posted January 10, 2009 Hi all, I wrote some code for a user login system that uses sessions to hold the user's login name so it can be referenced against later on in other scripts. Basically the flow of my code was that when a user log in and authenticates successfully, the $_SESSION['userLogin'] variable would be set. If that session value doesn't exist - the user is not logged in. Recently, I have tried using my PHP interface to access my data, but I can't login. When I submit my username and password the scripts redirect back to the login page. I have tracked it down to the problem of the $_SESSION['userLogin'] not being set, or that the session_is_registered('userLogin'); function returning the wrong value. When I set the $_SESSION variable my code reads: [userLogin.php] $localRowData = mysql_fetch_assoc($localDBResult); if (crypt($_POST['userPassword'], $localRowData['userPassword']) == $localRowData['userPassword']) { session_start(); $_SESSION['userLogin'] = $_POST['userLogin']; header("Location: ../pages/hisbContents.php"); } else { # password mismatch print("Incorrect password. Try again.<br/>\n"); } the hisbContents.php file has an include that checks if the session is active [hisbUserSessionCheck.php] session_start(); if (!session_is_registered('userLogin')) header("Location: ../pages/userLogin.php"); At this point, the code flow fails and returns to the user login form page. Am I assigning the value to the $_SESSION values correctly? Or is there any other reason why session_is_registered() is returning false? Is it perhaps that session_start() is called twice? I have NOT updated PHP, MYSQL, or Apache at any point since it last worked. I have only updated WinXP to SP3 (on which all the server software resides). Link to comment https://forums.phpfreaks.com/topic/140254-solved-session_is_registered-setting-_session-variables/ Share on other sites More sharing options...
xtopolis Posted January 10, 2009 Share Posted January 10, 2009 on hisbUserSessionCheck.php do a print_r($_SESSION); die(); and see if it even got passed the session variable correctly/at all. work backwards from there to see where it drops the ball FYI: updating to SP3 could have changed apache/mysql/php without directly telling you. Link to comment https://forums.phpfreaks.com/topic/140254-solved-session_is_registered-setting-_session-variables/#findComment-733913 Share on other sites More sharing options...
trq Posted January 10, 2009 Share Posted January 10, 2009 session_is_registered has long been depricated, simply use isset instead. if (!isset($_SESSION['userLogin'])) Link to comment https://forums.phpfreaks.com/topic/140254-solved-session_is_registered-setting-_session-variables/#findComment-733916 Share on other sites More sharing options...
Catfish Posted January 10, 2009 Author Share Posted January 10, 2009 on hisbUserSessionCheck.php do a print_r($_SESSION); die(); and see if it even got passed the session variable correctly/at all. work backwards from there to see where it drops the ball FYI: updating to SP3 could have changed apache/mysql/php without directly telling you. When I altered hisbUserSessionCheck.php to: <?php session_start(); print_r($_SESSION); die(); ?> It outputs an empty array (ie: "Array ( )" ) Which should mean that the assignment of the $_SESSION variables is not working right? So the assignment is taking place in userLogin.php. I edited the original code i Posted of userLogin.php to the following: $localRowData = mysql_fetch_assoc($localDBResult); if (crypt($_POST['userPassword'], $localRowData['userPassword']) == $localRowData['userPassword']) { session_start(); if ($_SESSION['userLogin'] = $_POST['userLogin']) header("Location: ../pages/hisbContents.php"); else { print('Session variable assignment failed.<br>'); die(); } } If I put a valid username and password, the scripts end up in hisbContents.php which includes hisbUserSessionCheck.php, which fails to find a value in $_SESSION. So is there something I am missing or has SP3 done something I don't know about? Link to comment https://forums.phpfreaks.com/topic/140254-solved-session_is_registered-setting-_session-variables/#findComment-734000 Share on other sites More sharing options...
nuttycoder Posted January 10, 2009 Share Posted January 10, 2009 if ($_SESSION['userLogin'] = $_POST['userLogin']) Should this not be : if ($_SESSION['userLogin'] == $_POST['userLogin']) **edit** ignore this I misread it. Link to comment https://forums.phpfreaks.com/topic/140254-solved-session_is_registered-setting-_session-variables/#findComment-734005 Share on other sites More sharing options...
Catfish Posted January 10, 2009 Author Share Posted January 10, 2009 No, the userLogin.php file (that code) is where the $_SESSION variable is assigned a value and created. Hence, = not ==. It is checed fr existance in hisUserSessionCheck.php now with isset($_SESSION['userLogin']) and that's the part of my scripts that now fail despite me changing nothing in my code. Frigging SP3... I swear its done something. Edit: I just found this: http://bugs.php.net/bug.php?id=16102 which seems to be discussing the problem I am having. My PHP is v 5.2.3 and that thread is from 2002, so I don't know if my PHP install has done some sort of auto-update or if 5.2.3 has the same bug in it. I'm pretty sure 5.2.3 is the original version I installed. Link to comment https://forums.phpfreaks.com/topic/140254-solved-session_is_registered-setting-_session-variables/#findComment-734006 Share on other sites More sharing options...
Catfish Posted January 10, 2009 Author Share Posted January 10, 2009 [sun Jan 11 01:24:32 2009] [error] [client 192.168.1.81] PHP Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\\DOCUME~1\\Catfish\\LOCALS~1\\Temp\\php\\session) in Unknown on line 0, referer: http://mab/hisb/pages/userLogin.php I have found the culprit. Somehow I lost the php\session folder from a Temp directory buried in Windows' spastic file layout. Why session data wouldn't be held in the php folders or the apache folders is beyond me. Anyway, I remade C:\\DOCUME~1\\Catfish\\LOCALS~1\\Temp\\php\\session folder and now the session variables are set correctly! Yippee for me! Now I just have to put my code back how it was. Thans for the help anyway, it helped me narow it down and not lose determination to fix this. Link to comment https://forums.phpfreaks.com/topic/140254-solved-session_is_registered-setting-_session-variables/#findComment-734019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.