RE: [PHP] Sessions

From: Date: Mon, 05 Aug 2002 16:28:59 +0000
Subject: RE: [PHP] Sessions
Groups: php.general 
Request: Send a blank email to php-general+get-111224@lists.php.net to get a copy of this message
> session_register("myVar"); > $myVar = "hello"; > > My problem arises when I try to output the variables further > down the page > using $HTTP_SESSION_VARS['myVar'] it just doesn't display > anything unless I > refresh the page then it works ok. I am assuming you have register_globals turned on in this answer. If it is off, delete this message now ;) The trick here is that PHP doesn't store the values of session variables to the $HTTP_SESSION_VARS array until the script ends. So on the current page, the array is empty. On the next page, the values are there. To access (display or assign to) the variable on the current page, just use the session variable, e.g., $myVar = "hello"; echo $myVar; Kirk

« previous php.general (#111224) next »