note 24767 added to ref.session

From: Date: Wed, 28 Aug 2002 07:44:35 +0000
Subject: note 24767 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-35846@lists.php.net to get a copy of this message
I'm writing my first PHP application and I?ve tested the saving of the session variables (I use PHP 4.0.6 on SuSE Linux). I've noticed the following: 1. If register_globals is ON, the variables cannot be seen in another page if you don't issue a session_register() after you set the variables. For example the following code: <?php session_start (); $HTTP_SESSION_VARS[ 'testvar'] = "variable transmission test"; $testvar = 'modified'; echo "<a href= \"./secpage.php\">Link</a>"; ?> won't display anything in a second page generated by the code: <?php session_start (); echo "Second Page!"; echo "<br></br> "; if (isset($HTTP_SESSION_VARS[ 'testvar'])) { echo "HTTP_SESSION_VARS: " . $HTTP_SESSION_VARS[ 'testvar']; }; echo "<br></br> "; if (isset($testvar)) { echo "testvar: ". $testvar; }; ?> After I've added the session_register('testvar') line after setting the variables, the following is displayed in the second page: HTTP_SESSION_VARS: modified testvar: modified These is strange because the manual specify not to use session_register if we use $HTTP_SESSION_VARS. 2. If register_globals is off, you don't need to use session_register('testvar') but in the second page displays: HTTP_SESSION_VARS: variable transmission test The conclusion is that if you want your code to work with register_globals set either to On or OFF you must use session_register(). You must also use only $HTTP_SESSION_VARS to set the variable. -- http://www.php.net/manual/en/ref.session.php http://master.php.net/manage/user-notes.php?action=edit+24767 http://master.php.net/manage/user-notes.php?action=delete+24767 http://master.php.net/manage/user-notes.php?action=reject+24767

« previous php.notes (#35846) next »