dptpn06684 2011-03-10 10:30
浏览 69

无法向$ _SESSION添加新值

I've a very strange problem with a session variable. This var is an associative array. I create this in a page (page A) with a lot of filterable items. I save filters in a session var

$_SESSION['filter'] = Array ( 'm' => 'acrylic', 'a' => 'P', 'c' => 1960 );

the user can go to a detail page (page B) but here I have

$_SESSION['filter'] = Array ( 'm' => 'acrylic', 'a' => 'P');

the strange is that when I go i the detail page I miss the last item in the associative array so I can't go back with the right filter info.

I build the session var in this function, the options are passed in the URL example: http://www.web.com/artworks/a-P/c-1960/o-private+collection

the argument $args with this URL will be this array('a-P', 'c-1960', 'o-private+collection')

private function filter($args){
        // options
        $f = array('a','c','u','t','m','o');
    $a = array();

    foreach($args as $i){
        $t = explode('-', $i);
        if (in_array($t[0], $f)){
            $a[$t[0]] = urldecode($t[1]);
            $this->suffix .= '/'.$i;
        }
        else if(is_numeric($i))
            $a['pp'] = intval($i);
    }
    $_SESSION['filter'] = $a;

    return $a;
}

I call this in page A, In the page B I don't call this function the only interaction is

if (isset($_SESSION['filter'])){
print_r($_SESSION);
...

Someone can help me? Thanks

  • 写回答

2条回答 默认 最新

  • duang8642 2011-03-10 10:35
    关注

    You have to call session_start somewhere in your script before adding new values into $_SESSION, otherwise they will not persist. Do you do that?

    评论

报告相同问题?

悬赏问题

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