2013-03-16 3 views
0

사용자 로그인과 로그 아웃/세션 만료 정보를 데이터베이스에 추가하고 싶습니다. 정상적인 로그인과 로그 아웃은 쉽지만 진행 방법을 알 수는 없습니다 자동 세션 만료.Zend Auth에서 사용자 세션이 만료되었을 때 만료 시간을 기록하는 방법

내 인증은 다음과 같이 작동합니다.

내 로그인 컨트롤러 액션 나는이를 수행 할 핵심 PHP 나 젠드 기능이 없다는 것을 두려워

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

사용자가 실제로 로그 아웃하지 않으면 세션의 마지막 타임 스탬프를 확인하기 위해 다른 HTTP 요청이 필요합니다. 그러나 세션이 20 분 동안 지속되면 해당 기간 내에 새로 고쳐지지 않은 세션은 더 이상 활성화되지 않으며 정기적으로 데이터베이스 레코드를 업데이트 할 예정입니다. – AlexP

답변

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 !"; 
      } 
     } 

하여 인증 방법, 세션 시간 초과가 실행되지 않습니다 백그라운드에서. 시간 초과 된 세션이 다른 요청을하지 않는 한 세션이 시간 초과되었는지 여부를 알 수 없습니다.

메소드 중 하나는 작업에 대한 ajax 요청을 작성하여 시간 초과가 없는지 확인하고 해당 작업에서 db를 업데이트하는 것입니다.

관련 문제