mads Posted July 14, 2009 Share Posted July 14, 2009 I have no idea why, but sometimes my session variable disappears. After having stared at it for two days, I guess it's time to cry for help... This is how I set the variable and later try to use it again: 1) I'm creating a session in header.php (a file that is loaded everytime a webpage is displayed): session_start(); ... $_SESSION['displaymode'] = "abe"; 2) I'm using the variable in go.php (which does not load header.php when it is displayed): session_start(); ... if(isset($_SESSION['displaymode'])) { $displaymode = $_SESSION['displaymode']; } Can anyone see why my session variable disappears? isset() returns false approx. 50% of the time and I have absolutely no idea why Thanks a lot, Mads Quote Link to comment https://forums.phpfreaks.com/topic/165894-my-session-variable-disappears/ Share on other sites More sharing options...
RussellReal Posted July 14, 2009 Share Posted July 14, 2009 session files getting deleted? set your session directory somewhere outside of the usual temporary directory and your hosting service providers won't touch em Quote Link to comment https://forums.phpfreaks.com/topic/165894-my-session-variable-disappears/#findComment-875030 Share on other sites More sharing options...
phporcaffeine Posted July 14, 2009 Share Posted July 14, 2009 That is true. Often times 3rd party hosts will whack the /tmp folder randomly for security purposes. That seems likely since you can't see a reliable pattern. Other than that, I would need to see more of your code. Quote Link to comment https://forums.phpfreaks.com/topic/165894-my-session-variable-disappears/#findComment-875086 Share on other sites More sharing options...
mads Posted July 15, 2009 Author Share Posted July 15, 2009 Sounds like a good idea, I'll try to add session_save_path() call and see what happens. Thanks a lot for the help. Quote Link to comment https://forums.phpfreaks.com/topic/165894-my-session-variable-disappears/#findComment-875665 Share on other sites More sharing options...
mads Posted July 19, 2009 Author Share Posted July 19, 2009 That didn't help I added session_save_path("mysessions") right before session_start() in header.php. Afterwards, I can see the session files being created in the "mysessions" directory on the webserver, but the session variable still doesn't exist when I need it in go.php Any other ideas on what might be going wrong? Thanks again, Mads Quote Link to comment https://forums.phpfreaks.com/topic/165894-my-session-variable-disappears/#findComment-878307 Share on other sites More sharing options...
xnowandtheworldx Posted July 19, 2009 Share Posted July 19, 2009 Sometimes I had to use if(!empty($_SESSION['session_name'])) { //code here; } for some reason sometimes $_SESSION would be set, and would trigger a false positive. So try that out and hopefully it might help you out. Quote Link to comment https://forums.phpfreaks.com/topic/165894-my-session-variable-disappears/#findComment-878309 Share on other sites More sharing options...
mads Posted July 22, 2009 Author Share Posted July 22, 2009 Sometimes I had to use if(!empty($_SESSION['session_name'])) { //code here; } for some reason sometimes $_SESSION would be set, and would trigger a false positive. So try that out and hopefully it might help you out. Tried that, didn't work Quote Link to comment https://forums.phpfreaks.com/topic/165894-my-session-variable-disappears/#findComment-880217 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.