RE: [PHP] Session data getting lost

From: Date: Wed, 17 Sep 2003 20:37:55 +0000
Subject: RE: [PHP] Session data getting lost
Groups: php.general 
Request: Send a blank email to php-general+get-162918@lists.php.net to get a copy of this message
[snip] So your telling me that all variables defined in the global scope are automatically added to the $_SESSION array...? Not true I think.... [/snip] You're right of course. I went back to your original code and stripped it back some <?php session_start(); $test = -1; echo $_SESSION['test']."\n"; $test = 999; $_SESSION['test'] = $test; echo $_SESSION['test']."\n"; ?> The logic is incorrect, when you reload the page $test gets set to -1 before your echo statement. After your echo statement it gets set to 999. On reload it again gets set to -1 before your echo. The second echo is always right (for what you want). If you comment out $test = -1; both echos come back correctly. Since you have declared $_SESSION['test'] once and the session is still in effect on the reload the first echo comes back -1 since that is what the declared variable is now worth. Make sense?

« previous php.general (#162918) next »