ryanmetzler3 Posted August 30, 2013 Share Posted August 30, 2013 (edited) I have a website that runs using sessions. When the login page is submitted it starts a session and defines a username and user id. Then I have the following code pasted at the top of every page: session_save_path('/home/users/web/b2719/ipg.trackyourgraffiticom/cgi-bin/tmp'); session_start(); $username = $_SESSION['username']; $userid = $_SESSION['userid']; it was working fine and I did not change a thing but now when I log in, it logs me out immediately. So I did this: session_save_path('/home/users/web/b2719/ipg.trackyourgraffiticom/cgi-bin/tmp'); session_start(); ini_set("display_errors", "1"); error_reporting(-1); $username = $_SESSION['username']; $userid = $_SESSION['userid']; Just to see what errors came out. It says this: Notice: Undefined index: username in /hermes/bosoraweb068/b2719/ipg.trackyourgraffiticom/includelog.php on line 6 Notice: Undefined index: userid in /hermes/bosoraweb068/b2719/ipg.trackyourgraffiticom/includelog.php on line 7 Any ideas? because I can't figure out why that would make it not work. Edited August 30, 2013 by ryanmetzler3 Quote Link to comment https://forums.phpfreaks.com/topic/281686-site-was-just-working-now-its-not-sessions/ Share on other sites More sharing options...
denno020 Posted August 30, 2013 Share Posted August 30, 2013 What happens if you put session_start() before your session_save_path()? session start is supposed to be the very first line in your file, but not sure if that counts in regards to another session setting. If that's not the problem then you need to look at your login handler, specifically, where you're setting the username session variable. Make sure that's working. Denno Quote Link to comment https://forums.phpfreaks.com/topic/281686-site-was-just-working-now-its-not-sessions/#findComment-1447427 Share on other sites More sharing options...
Andy-H Posted August 30, 2013 Share Posted August 30, 2013 (edited) What happens if you put session_start() before your session_save_path()? session start is supposed to be the very first line in your file, but not sure if that counts in regards to another session setting. If that's not the problem then you need to look at your login handler, specifically, where you're setting the username session variable. Make sure that's working. Denno From session_save_path Session data path. If specified, the path to which data is saved will be changed. session_save_path() needs to be called before session_start() for that purpose. Also, session_start isn't "supposed" to be the very first line in your file, although that is common practice, it just needs to be called before any output has been sent to the client. @OP Is there any reason you're modifying the session save path? Is the directory you're setting it to readable and writable by the user your server is running under? (probably www-data) Edited August 30, 2013 by Andy-H Quote Link to comment https://forums.phpfreaks.com/topic/281686-site-was-just-working-now-its-not-sessions/#findComment-1447434 Share on other sites More sharing options...
mac_gyver Posted August 30, 2013 Share Posted August 30, 2013 your code needs to have the display_errors/error_reporting settings as the first php statements so that if there are any errors when the session_save_path() and session_start() statements run you would know about them. what is your code that is setting the $_SESSION variables? are you sure they are even being set in the first place? Quote Link to comment https://forums.phpfreaks.com/topic/281686-site-was-just-working-now-its-not-sessions/#findComment-1447437 Share on other sites More sharing options...
ryanmetzler3 Posted August 31, 2013 Author Share Posted August 31, 2013 From session_save_path Session data path. If specified, the path to which data is saved will be changed. session_save_path() needs to be called before session_start() for that purpose. Also, session_start isn't "supposed" to be the very first line in your file, although that is common practice, it just needs to be called before any output has been sent to the client. @OP Is there any reason you're modifying the session save path? Is the directory you're setting it to readable and writable by the user your server is running under? (probably www-data) Thanks for the suggestion. I modified the location because my server uses shared hosting. I did not really understand why but they said you need to change your session_save_path to a file in your directory to avoid problems. I got it working again. It was the strangest thing. I swear it was working fine and I did not change anything. Then it stopped working and I was messing with it for hours. Then I finally just reverted back to the original before I was about to go to bed and it works fine? Some kind of which craft for sure. Quote Link to comment https://forums.phpfreaks.com/topic/281686-site-was-just-working-now-its-not-sessions/#findComment-1447489 Share on other sites More sharing options...
ryanmetzler3 Posted August 31, 2013 Author Share Posted August 31, 2013 your code needs to have the display_errors/error_reporting settings as the first php statements so that if there are any errors when the session_save_path() and session_start() statements run you would know about them. what is your code that is setting the $_SESSION variables? are you sure they are even being set in the first place? Thanks for the suggestion. It was the strangest thing. I swear it was working fine and I did not change anything. Then it stopped working and I was messing with it for hours. Then I finally just reverted back to the original before I was about to go to bed and it works fine? Some kind of which craft for sure. Quote Link to comment https://forums.phpfreaks.com/topic/281686-site-was-just-working-now-its-not-sessions/#findComment-1447490 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.