初始化后,php会话变量不更新二维数组

I'm almost embarrassed to ask because it seems so simple, but I can't get it to update.

When the user logs in I set the session vars like array('users'=>array('timezone'=>'America/los Angeles'));

I can then retrieve the data as follows: $_SESSION['users']['timezone']

and it works fine.

However in the user profile page the user can change their timezone and when I try to update the $_SESSION as follows it doesn't work:

$_SESSION['users']['timezone'] = 'America/Denver';

What am I doing wrong?

--- More code as requested -------

I found that the session variables were being set by a function inside of a class

Here's the function:

function session_var_register($object_name, $var_value)
    {
        $_SESSION[$object_name]=$var_value;
    }

Here's how the function got called:

$gf->session_var_register("users", $user_array)

Users Array looks like array('users'=>array('timezone'=>'America/los Angeles'));

I don't understand why this doesn't work. I was able to get around the problem though by bypassing the function call and just creating the array like:

$_SESSION['users'] = $user_array;

But for knowledge reasons and if anyone else comes along this post, could anyone explain what the function was doing different? There were no errors thrown, just would not allow me to assign anything to the session variable once it was registered via the function...almost acted like it became read_only once instantiated.

Make sure you session_start() on every page that accesses the $_SESSION variable.

Sounds like the code that updates it may not be getting executed. You might try putting some kind of debugging statement before this assignment like an echo to verify that the action is being taken.

Following on from Scott's reply, double checking your session is started is a good "start".

There's a good tip here which you may find useful in debugging.

re-initialize your session id. That way you are sure it has a new spanking id to store your variables.

Are you doing a redirect soon after this code?

Do a session_write_close() before doing a redirect so that session vars are stored again before redirecting.