$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: [EMAIL PROTECTED]

-----Original Message-----
From: Richard Fox [mailto:[EMAIL PROTECTED]]
Sent: 04 March 2002 15:26
To: [EMAIL PROTECTED]
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!





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to