【发布时间】:2013-03-16 22:42:22
【问题描述】:
我想将用户登录和注销/会话到期信息添加到数据库中,正常登录和注销很容易,但我不知道如何进行自动会话到期。
我的身份验证如下所示。
我的登录控制器操作
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;
}
【问题讨论】:
-
如果用户没有真正“注销”,就无法检查他们的过期时间(您需要另一个 HTTP 请求来检查会话的最后一个时间戳)。但是,如果您的会话持续 20 分钟,那么可以公平地说,在该时间段内未刷新的任何会话都不再处于活动状态,您可以有一个计划任务来定期更新这些数据库记录。
标签: php zend-framework zend-auth zend-session