Running into a slight buggy problem here..

I'm trying to setup and use session variables for this application. When a user logs in, I'd like to register a userID session variable and an authenticated session variable. I'd then like to use these variables throughout the site.

When a user submits their username and password to portal.php, It calls a function that attempts to authenticate the username and password. If successful, it should setup to session variables.

the format looks like this:

function auth($username, $password) {
GLOBAL $s_userID, $s_AUTH;

// Grab user info from database, if its all good do the following:
unset($s_userID, $s_AUTH);
session_register('s_userID');
session_register('s_AUTH');
// Here's where I tried different things
// Option a)
$GLOBALS['s_userID'] = // userid from db
$GLOBALS['s_AUTH'] = true;
// Option b)
$HTTP_SESSION_VARS["s_userID"] = // userid from db
$HTTP_SESSION_VARS["s_AUTH"] = true;
return true; // if authenticated
}

Then, in my portal page.. i had something like
if (auth($username, $password)) {
Header("Location: somewhere");
} else {
// not authenticated
}

The problem here in lies with where i go after the header is sent.

1) If I use HTTP_SESSION_VARS, $HTTP_SESSION_VARS["s_userID"] will not hold its value where "somewhere" is in the header redirection.

I believe this is because register_globals is actived in my php.ini...(read about problems here in php.net) ...

Is there anyway I can reference these variables safely (preferably using $HTTP_SESSION_VARS instead of GLOBALS throughout my pages? I constantly have to check session_is_registered("s_AUTH") to make sure the GLOBALS didn't come from somewhere other than the session variable.

Anyone run into this same problem?

    5 months later

    I have just recently found a method of being able to use $HTTP_SESSION_VARS on every server regardless of the setting of register_globals. Its simple, but works a treat. Just use

    ini_set("register_globals", "0");

    somewhere in the top of every calling script and you'll be able to use HTTP_SESSION_VARS.
    Hope this helps.

      6 months later

      I tried calling
      ini_set("register_globals", "0") at the top of my script but was still unable to use $HTTP_SESSION_VARS . I am using PHP 4.0.6 and register_globals is set to ON

        2 months later

        It worked fine with me?
        ??????

        yem huynh wrote:

        I tried calling
        ini_set("register_globals", "0") at the top of my script but was still unable to use $HTTP_SESSION_VARS . I am using PHP 4.0.6 and register_globals is set to ON

          Write a Reply...