[PHP] registering session variables doesn't work in functions From: A Complete Luser (acompleteluser <email protected>)
Date: 12/23/00

Hi all,

Don't know if anyone has seen this yet, but if you know the answer to
why this is happening and if it can be fixed, I'd really appreciate
the help :(

I am starting to use sessions. At this stage I am only using them in
cookies. This is because I haven't worked out how to use URL's for the
session id at all.

In my login.php, I check a users login. If the username and password
match the entry in the database, I want to start a session. I then
call a function in a library of functions that I am using here...

So the code looks as follows :

require("../include/Authfunctions.inc.php");

session_start();

if (!$user_auth || $user_auth == "")
{

    check_user_auth($HTTP_SERVER_VARS,$HTTP_POST_VARS);

}

If I try and do the session_register("variable_name") in the
check_user_auth function, then the sess_blah file in /tmp contains the
names of all the variables that I am trying to register but no
values. If however, I do the following :

require("../include/Authfunctions.inc.php");

session_start();

if (!$user_auth || $user_auth == "")
{

    $user_details = check_user_auth($HTTP_SERVER_VARS,$HTTP_POST_VARS);

    $user_level = $user_details["user_level"];
    $user_first_name = $user_details["user_first_name"];
    $user_last_name = $user_details["user_last_name"];
    $user_email_address = $user_details["user_email_address"];
    $user_name = $user_details["user_name"];
    $user_auth = $user_details["user_auth"];

    session_register("user_name");
    session_register("user_level");
    session_register("user_first_name");
    session_register("user_last_name");
    session_register("user_email_address");
    session_register("user_auth");
    session_register("acl_level");

}

everything works fine. The session is setup properly and I simply have
to do a session_start() at the top of every page where I want to have
access to the session variables.

My main question is why doesn't registering session variables in
functions work, but it does work fine if I return the values to the
calling functions and register them there?

-- 
A Complete Luser <acompleteluser <email protected>>

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>