Han*_*nes 8 php session zend-framework lifetime zend-auth
我使用Zend_Auth作为我的一个项目,但到目前为止还没有弄清楚如何设置会话的生命周期,或者如何扩展它(假设它应该运行5分钟并且应该在用户做出动作时重置为),这是我的初始化代码:
$authAdapter = new Zend_Auth_Adapter_DbTable($this->_model->pdo);
$authAdapter->setTableName('normal_folks')
->setIdentityColumn('username')
->setCredentialColumn('password');
$post = $this->_request->getPost();
$authAdapter->setIdentity($post['username'])
->setCredential($post['password']);
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if($result->isValid())
{
$userInfo = $authAdapter->getResultRowObject(null, 'password');
$authStorage = $auth->getStorage();
$authStorage->write($userInfo);
if(strlen($post['refferer']) > 1){
header("Location: ".$post['refferer']);
}elseif(strlen($this->_request->getParam('ref_action')) > 1){
Zend_Controller_Action::_forward($this->_request->getParam('ref_action'),"admin",null,null);
}else{
Zend_Controller_Action::_forward("index","admin",null,null);
}
}
Run Code Online (Sandbox Code Playgroud)
蚂蚁这个我如何检查用户是否登录:
if(Zend_Auth::getInstance()->hasIdentity()){
echo "Woho!";
}else{
die("invalid-identity");
}
Run Code Online (Sandbox Code Playgroud)
它可能就在我面前,但我无法理解,帮助?请?好吗?:d
Gor*_*don 14
身份验证状态存储在已注册的Auth Storage中.默认情况下这是Zend_Session.您可以设置Zend_Auth命名空间的到期时间,例如
$namespace = new Zend_Session_Namespace('Zend_Auth');
$namespace->setExpirationSeconds(300);
Run Code Online (Sandbox Code Playgroud)
您还可以全局配置Zend_Session via
Zend_Session::setOptions(array(
'cookie_lifetime' => 300,
'gc_maxlifetime' => 300));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9747 次 |
| 最近记录: |