douxian1923 2010-07-14 20:10
浏览 47

初始化后,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.

  • 写回答

5条回答 默认 最新

  • dongyou7472 2010-07-14 20:15
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大