0

我想将用户登录和注销/会话到期信息添加到数据库中,正常登录和注销很容易,但我不知道如何进行自动会话到期。

我的身份验证如下所示。

我的登录控制器操作

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;
    }
4

1 回答 1

0

恐怕没有核心 PHP 或 Zend 函数来执行此操作,会话超时不会在后台运行。除非超时会话发出另一个请求,否则甚至不可能知道会话是否超时。

其中一种方法是向操作发出 ajax 请求以检查超时并在该操作中更新您的数据库。

于 2013-03-17T04:27:31.277 回答