RE: [PHP] [Q] session variables wouldn't keep contents.

From: Date: Wed, 14 Mar 2001 20:50:37 +0000
Subject: RE: [PHP] [Q] session variables wouldn't keep contents.
Groups: php.general 
Request: Send a blank email to php-general+get-43911@lists.php.net to get a copy of this message
> -----Original Message----- > From: Chung Ha-Nyung [mailto:alita@kldp.org] > > My second example program. > ---- a.php ---- > <?php > session_start(); > session_register("name"); > $HTTP_SESSION_VARS["name"] = "test"; > > echo session_encode(); > ?> > ---- a.php ---- > result is as following. > ==================== > !name| > ==================== > > Anybody has some clues about it? why session variables' contents > wouldn't stored. Chung, this is a complicated topic! See http://www.php.net/manual/cs/ref.session.php, although the documentation there does not go into much detail. $HTTP_SESSION_VARS["name"] and $name are not the same variables, *while on the current page*. To see this, add these lines to your code above just above the echo session_encode() line: $name = "another test"; echo "name is ".$name."<br>"; echo "array element name is ".$HTTP_SESSION_VARS["name"]."<br>"; See what session_encode() outputs now? name|s:7:"another test"; Another way to think of these two variables is $GLOBALS["HTTP_SESSION_VARS"]["name"] and $GLOBALS["name"]. Now, depending on if register_globals is enabled or disabled in php.ini, determines what happens to these two variables when you *redirect to the next page*. I suggest you write some code that echo's out all elements of $GLOBALS, including arrays. Then play around with assigning a value to $HTTP_SESSION_VARS["name"] and leaving $name blank, and vice-versa. See what happens to their values on the current page and then redirecting to another page. Repeat with register_globals enabled and then disabled in php.ini. So, your original code above assigns the value "test" to an element of the $HTTP_SESSION_VARS array. In my setup, *with register_globals enabled*, session_encode() only encodes $GLOBALS["someVariableName"], and not elements of the array $GLOBALS["HTTP_SESSION_VARS"]. I guess the conclusion is that $HTTP_SESSION_VARS is not itself a registered variable, although its elements may be, so that session_encode() doesn't encode it. Clear as mud? Yeah, to me to... Good luck! Kirk

« previous php.general (#43911) next »