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
work:

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

But this will:

function setFlavor ($flavor)
{
        // THIS WILL!!!
        session_start();
        global $sess_flavor;
        session_register("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?

Thanks,
Chris


-- 
PHP General Mailing List (http://www.php.net/)
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