tags:

views:

22

answers:

3

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.

+2  A: 

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

Scott Saunders
that's `session_start()` (http://php.net/session_start)
Kris
Thanks Kris. I caught the mix up after I submitted and have edited to fix the answer. I can never keep PHP function names straight :)
Scott Saunders
thanks. checked it and session is started...var_dump($_SESSION) showed everything...but still can't assign to it?
Ronedog
You may want to show more of your code then. There's no reason it shouldn't work based on what you've described so far.
Scott Saunders
A: 

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.

jMerliN
did that and it is executing to that statement, but just doesn't assign to the session.
Ronedog
A: 

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.

danp