note 24767 deleted from ref.session by sniper

From: Date: Tue, 21 Jan 2003 03:14:55 +0000
Subject: note 24767 deleted from ref.session by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-42475@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.

« previous php.notes (#42475) next »