Session::isConcurrentSessionExists PHP 메소드

isConcurrentSessionExists() 공개 정적인 메소드

This is done as the following: UserA logs in with his session id('123') and it will be stored in the database. Then, UserB logs in also using the same email and password of UserA from another PC, and also store the session id('456') in the database Now, Whenever UserA performs any action, You then check the session_id() against the last one stored in the database('456'), If they don't match then log both of them out.
또한 보기: Session::updateSessionId()
또한 보기: http://stackoverflow.com/questions/6126285/php-stop-concurrent-user-logins
public static isConcurrentSessionExists ( ) : boolean
리턴 boolean
    public static function isConcurrentSessionExists()
    {
        $session_id = session_id();
        $userId = Session::get('user_id');
        if (isset($userId) && isset($session_id)) {
            $database = DatabaseFactory::getFactory()->getConnection();
            $sql = "SELECT session_id FROM users WHERE user_id = :user_id LIMIT 1";
            $query = $database->prepare($sql);
            $query->execute(array(":user_id" => $userId));
            $result = $query->fetch();
            $userSessionId = !empty($result) ? $result->session_id : null;
            return $session_id !== $userSessionId;
        }
        return false;
    }

Usage Example

예제 #1
0
파일: Auth.php 프로젝트: panique/huge
 /**
  * Detects if there is concurrent session (i.e. another user logged in with the same current user credentials),
  * If so, then logout.
  */
 public static function checkSessionConcurrency()
 {
     if (Session::userIsLoggedIn()) {
         if (Session::isConcurrentSessionExists()) {
             LoginModel::logout();
             Redirect::home();
             exit;
         }
     }
 }
All Usage Examples Of Session::isConcurrentSessionExists