Zend Auth Session Cookie

Tag: cookies , session-cookies , zend-auth , zend-session Author: zhaoxiaoran2009 Date: 2012-12-31

I'm stuck on a common problem but I don't really know how to get out.

The browsers don't keep the auth session. Here is my setup.

"application.ini"

resources.session.save_path = ROOT_DIR "/public/session"
resources.session.gc_maxlifetime = 864000
resources.session.remember_me_seconds = 864000

".htaccess"

php_value session.gc_maxlifetime 864000
php_value session.save_path /Users/user/mydomain.com/public/session/

"bootstrap.php" (_initSessionNamespaces it's the first method I call)

protected function _initSessionNamespaces()
{
    $this->bootstrap('session');
    Zend_Session::start();
}

"SigninController.php"

// set adapter
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('user')
->setIdentityColumn('email')
->setCredentialColumn('password')
->setCredentialTreatment($salt)
->setIdentity($values['email'])
->setCredential($values['password']);

$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);

if ($result->isValid()) {
    $user = $authAdapter->getResultRowObject();
    $auth->getStorage()->write($user);

    // init session cookie
    $session_auth = new Zend_Session_Namespace('identity');
    $session_auth->setExpirationSeconds(864000);

    return true;
}

the session file that has been created in the directory is this:

language|a:1:{s:6:"locale";s:2:"en";}identity|a:2:{s:14:"filterDistance";i:5;s:5:"email";s:15:"[email protected]";}Zend_Auth|a:1:{s:7:"storage";O:8:"stdClass":20:{s:2:"id";s:20:"8c3b329b0f3d71f4566c";s:12:"date_created";s:19:"2012-12-19 20:30:29";s:12:"date_updated";s:19:"2013-01-12 00:02:19";s:14:"date_lastlogin";s:19:"2013-01-16 15:30:01";s:7:"site_id";s:4:"this";s:14:"site_lastlogin";s:4:"this";s:6:"active";s:1:"1";s:4:"role";s:5:"admin";s:8:"username";s:5:"test";s:8:"password";s:40:"63fb7f1941083ca0284481d8ad557e2b0c5bf5f4";s:4:"salt";s:40:"70be1adbff1c0bd6f82sc1fcaf6d2fef3c869b6c";s:10:"first_name";s:5:"pippo";s:9:"last_name";s:0:"";s:5:"email";s:15:"[email protected]";}}__ZF|a:1:{s:9:"Zend_Auth";a:1:{s:3:"ENT";i:865358347332;}}

And usually in a Controller I call the user info in this way

$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
    $this->info = $auth->getIdentity();
}

When I restart the browser it create a new empty session file like this:

language|a:1:{s:6:"locale";s:2:"it";}

I'm stuck here for 2 days... what can I do??

Best Answer

I solved it adding this in application.ini

resources.session.cookie_lifetime = 864000

I think this could help someone :)