我想将用户登录和注销/会话过期信息添加到数据库中,它很容易正常登录和注销,但我无法弄清楚如何继续自动会话到期。
我的身份验证功能如下所示。
我的登录控制器操作
if ($request->isPost()) {
$data = $request->getParams();
$userModel = new Application_Model_User_DbTable();
if ($user = $userModel->login($data['email'], $data['password'])) {
/* check if user is activated or not */
if ($user['status'] == 0) {
$this->view->loginerror = "<b>Account not active :</b> Please wait for admin to activate your account";
}elseif($user['status'] == -1){
$this->view->loginerror = "<b>Account Suspended :</b> Your account is suspeneded you must contact admin to continue";
}else {
/* Store authentication data in session */
$auth = Zend_Auth::getInstance();
$identity = Zend_Auth::getInstance()->getStorage();
$identity->write($user);
$this->_redirect('/fax');
}
} else {
$this->view->loginerror = "<b>Invalid login :</b> Email or passsword is invalid !";
}
}
在我的用户控件中验证方法
function authenticate($email, $password) {
$where = array();
$where[] = $this->getAdapter()->quoteinto('email = ?', $email);
$user = $this->fetchRow($where);
if (isset($user['email'])) {
$salt = $user['password_salt'];
if (sha1($password . $salt) == $user['password']) {
/** here i will add login session info**/
return $user;
}
return false;
}
return false;
}
答案 0 :(得分:0)
我担心没有核心PHP或Zend函数来执行此操作,会话超时不会在后台运行。除非超时会话发出另一个请求,否则甚至无法知道会话是否超时。
其中一种方法是对操作发出ajax请求以检查超时并在该操作中更新数据库。