ZF-11502: Zend_Session_Namespace does not work in chrome browser.

Description

Zend_Session_Namespace does not work in chrome browser. The site is sandbox.oggiedomani.org. The navigation choice is saved in session. It works in Firefox 4 and IE 9. However, Chrome browser doesn't store the session. I use Zend Session as following


$restNamespace = new Zend_Session_Namespace('explorenyc');
if(!isset($restNamespace->boro)){
    $restNamespace->boro = array();
}
if(!empty($input->do)){
    if($input->do=="add" && !empty($input->val)){
        if($input->obj=="cuisine"){
            $restNamespace->cuisine[$input->val] = 1;
        }

        else if($input->obj=="boro"){
            $restNamespace->boro[$input->val] = 1;
        }
                            
            
        else if($input->obj=="neighborhood"){
            $restNamespace->neighborhood[$input->val] = 1;
        }
        
    }
    if($input->do=="clear" && !empty($input->val)){
        if($input->obj=="cuisine"){
            unset($restNamespace->cuisine[$input->val]);
        }
        else if($input->obj=="boro"){
            unset($restNamespace->boro[$input->val]);
        }
        else if($input->obj=="neighborhood"){
            unset($restNamespace->neighborhood[$input->val]);
        }
    }
    if($input->do=="clearall"){
        unset($restNamespace->cuisine);
        unset($restNamespace->boro);
        unset($restNamespace->neighborhood);
    }
}

Comments

Let me know any suggestions to resolve the problem. The issue is replicated on localhost using wamp. I appreciate your help.

This problem also causes Zend_Auth to fail in Chrome under PHP 5.3 only. Login is possible but Zend_Auth::getInstance()->hasIdentity() returns false because of the session problem.

Anything going on with this?

Zend session doesn't work well with associative arrays. I got it working with indexed array.

<?php

class IndexController extends Zend_Controller_Action {

public function init()
{
    /* Initialize action controller here */
}

public function indexAction()
{
    // action body
    $test = new Zend_Session_Namespace('test');
    if(!empty($test->one)){
        $one = $test->one;
        $one = " abc ".$one;
        $test->one = $one;
    }
    else{
        $test->one = "hello";
    }
    $this->view->test = $test->one;

    if(!empty($test->sal)){
        $sal = $test->sal;
        $pos = rand(0, 9);
        $sal[$pos] = rand(30000, 170000);
        $test->sal = $sal;

}
    else{
        $arr = array();
        for($i=0; $i<10; $i++){
            $arr[$i] = 1;
        }
        $test->sal = $arr;

    }

    $this->view->sal = $test->sal;
}

}

This is actually a bug in PHP, $_REQUEST does not contain $_COOKIE anymore. The php.ini setting request_order = "GPC" fixes the problem.

I was somehow mistaken, the request_order = "GPC" setting does NOT fix the problem.

Another solution is to avoid using session all together. I can pass arguments in the query string instead: http://example.com/search/…

Well, if you use Zend_Auth that really doesn't help.

Set component and auto-reassign.

heard like a missing favicon.ico. chrome makes a new thread for requesting the favicon.ico. so if you handle 404 requests in a way with updating a session-cookie you will get a new session-id and your visible browser tab session has an other session than the "favicon" request! check your serverlogs and 404 handling.

Is there any solution? It's so annoying that all my ZF apps will not work well in Chrome.

Yes Sebastian Galenski, I found that problem too. I print the $response object in every preDispatch call in my bootstrap and Chrome always asks for the favicon.ico. Thank you so much!

This is not an issue with Zend Framework itself. It is an issue with how Chrome requests favicon files in parallel with the initial GET request.