使用 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);
}
}
Ant 这是我检查用户是否登录的方式:
if(Zend_Auth::getInstance()->hasIdentity()){
echo "Woho!";
}else{
die("invalid-identity");
}
它可能就在我面前,但我就是无法弄清楚,帮忙吗?请?漂亮吗? :D
i use Zend_Auth for one of my Projects, but so far haven't figured out how to set the Lifetime for the Session, or how to extend it (lets say it should run 5 minutes and should reset to that when the user makes an action), here is my Initialization code:
$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);
}
}
Ant this how i check if the user is logged in:
if(Zend_Auth::getInstance()->hasIdentity()){
echo "Woho!";
}else{
die("invalid-identity");
}
Its probably right there in front of me but I just can't figure it out, help? Please? Pretty Please? :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
身份验证状态存储在注册的身份验证存储中。默认情况下,这是
Zend_Session
。您可以设置过期时间< code>Zend_Auth 命名空间,例如您还可以 全局配置
Zend_Session
通过Authentication state is stored in the registered Auth Storage. By default this is
Zend_Session
. You can set an expiration time to theZend_Auth
namespace, e.g.You can also globally configure
Zend_Session
via如果您为 zend_auth 会话使用不同的命名空间,您可以这样做:
If you are using different namespace for zend_auth session you can do it like this: