RE: [PHP] Session variable scope - surprise!

From: Date: Mon, 04 Mar 2002 15:38:53 +0000
Subject: RE: [PHP] Session variable scope - surprise!
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-87105@lists.php.net to get a copy of this message
$HTTP_SESSION_VARS only gets populated when you load another page. Or refresh the current one. To use your example again... <?php function reg() { $test = 13; session_register("test"); echo "in reg(), test=<$test><br>"; } global $HTTP_SESSION_VARS; session_start(); $test = 12; reg(); if (session_is_registered("test")) { $tt = $HTTP_SESSION_VARS["test"]; echo "session variable test=<$tt><br>"; } else echo "You really don't know what you're doing, do you?<br>"; ?> Run this script, and it will give the output in reg(), test=<13> session variable test=<> But... Refresh the page, and you should see: in reg(), test=<13> session variable test=<12> Because $HTTP_SESSION_VARS gets populated. Its something to do with HTTP headers I think - can't remember exactly why, but I know what happens. HTH, ========================================== Richard Black Systems Programmer, DataVisibility Ltd - http://www.datavisibility.com Tel: 0141 435 3504 Email: rblack@datavisibility.co.uk -----Original Message----- From: Richard Fox [mailto:rfox@sbsii.com] Sent: 04 March 2002 15:26 To: php-general@lists.php.net Subject: RE: [PHP] Session variable scope - surprise! OK, but then how do you explain: <?php function reg() { $test = 13; session_register("test"); echo "in reg(), test=<$test><br>"; } global $HTTP_SESSION_VARS; session_start(); reg(); if (session_is_registered("test")) { $tt = $HTTP_SESSION_VARS["test"]; echo "session variable test=<$tt><br>"; } else echo "You really don't know what you're doing, do you?<br>"; ?> This still gives me the output: in reg(), test=<13> session variable test=<> Aaargh!

« previous php.general (#87105) next »