pthurmond Posted July 10, 2008 Share Posted July 10, 2008 I have a site that I have already started a session with session_start(), yet when I check the session superglobal with isset($_SESSION) it returns false. Now it was my understanding that once the session is started the session superglobal becomes immediately available. Does it not become available until I put a value into it? Quote Link to comment Share on other sites More sharing options...
Guest Xanza Posted July 10, 2008 Share Posted July 10, 2008 Not too sure about this... But try putting a value and post the results. Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 10, 2008 Share Posted July 10, 2008 $_SESSION should exist immediately after the session_start() call. Quote Link to comment Share on other sites More sharing options...
pthurmond Posted July 10, 2008 Author Share Posted July 10, 2008 Will it exist at all before running session_start? Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 10, 2008 Share Posted July 10, 2008 From my testing, no. There may be a directive that defines this somewhere though, I'm not sure. I can't see why it'd be defined by default. Quote Link to comment Share on other sites More sharing options...
pthurmond Posted July 10, 2008 Author Share Posted July 10, 2008 Hmm, well when I try to start a session it tells me that it is already started, yet when I then check to see if the session superglobal is available it says no. To make things even more confusing I save a variable to the superglobal then try to check it a few pages later and the data is gone. Quote Link to comment Share on other sites More sharing options...
discomatt Posted July 10, 2008 Share Posted July 10, 2008 Try this simple two page session test page1.php <?php session_start(); if ( !isset($_SESSION['counter']) ) $_SESSION['counter'] = 0; $_SESSION['counter']++; echo $_SESSION['counter'] . ' -> <a href="page2.php">To page2.php</a>'; ?> page2.php <?php session_start(); if ( !isset($_SESSION['counter']) ) $_SESSION['counter'] = 0; $_SESSION['counter']++; echo $_SESSION['counter'] . ' -> <a href="page1.php">To page1.php</a>'; ?> If that doesn't work, there's something wrong with your setup. You may be forcing cookies and have them disabled/blocked by your client as well. Quote Link to comment Share on other sites More sharing options...
pthurmond Posted July 10, 2008 Author Share Posted July 10, 2008 Actually I think I know the problem now. We are working in Expression Engine and instead of creating an extension, the other developer decided to start the session in the layout head template. Which leaves us with a session start location that is a bit unpredictable. So I think that the code execution order is part of the problem. I will work on developing an extension for it. 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.