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
 /**
  * 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