One of the annotations to the docs for session functions notes that if
you want to set a session variable inside a function, you have to call
session_start() BEFORE to use your global $varname statement. But
there's more to it than that.

After some very annoying trial and error, I disovered that this won't

function setFlavor ($flavor)
        // THIS WON'T WORK!!!!
        global $HTTP_SESSION_VARS;
        $HTTP_SESSION_VARS["sess_flavor"] = $flavor;

But this will:

function setFlavor ($flavor)
        // THIS WILL!!!
        global $sess_flavor;
        $sess_flavor = $flavor;

In other words, using $HTTP_SESSION_VARS won't work for writing a
session variable within a function. You have to use the bare varname.
What's odd is using $HTTP_SESSION_VARS to read a variable works fine.

Since I like to always use $HTTP_SESSION_VARS for safety, rather than
the bare varname, I'm not too thrilled with all this. Can anyone
explain why it's so?


PHP General Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to