我被一个常见的问题卡住了,但我真的不知道如何解决。
浏览器不保留验证会话。这是我的设置。
"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这是我调用的第一个方法)
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;
}
在目录中创建的会话文件如下:
language|a:1:{s:6:"locale";s:2:"en";}identity|a:2:{s:14:"filterDistance";i:5;s:5:"email";s:15:"test@test.com";}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:"test@test.com";}}__ZF|a:1:{s:9:"Zend_Auth";a:1:{s:3:"ENT";i:865358347332;}}
通常在控制器中我用这种方式调用用户信息
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$this->info = $auth->getIdentity();
}
当我重新启动浏览器时,它创建了一个新的空会话文件,如下所示:
language|a:1:{s:6:"locale";s:2:"it";}
我被困在这里2天…我能做什么?? 我把它添加到application.ini
resources.session.cookie_lifetime = 864000
我想这可以帮助到一些人:)