开发者

Cannot add new values to $_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开发者_如何学JAVA/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


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?


I don't know exactly but try with giving last varible value in quotes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜