Beispiel #1
0
 /**
  * Creates a new session for a given user.
  *
  * @param int  $userId       User's ID
  * @param bool $isPersistent Whether the session is persistent or not
  *
  * @return Session
  *
  * @throws Exception
  */
 public static function createSession($userId, $isPersistent = false)
 {
     self::validateIsPersistent($isPersistent);
     $creationDate = time();
     if ($isPersistent) {
         $expiryDate = strtotime(\PHPAuth\Configuration::SESSION_PERSISTENT_TIME);
     } else {
         $expiryDate = strtotime(\PHPAuth\Configuration::SESSION_NON_PERSISTENT_TIME);
     }
     $ipAddress = $_SERVER['REMOTE_ADDR'];
     $userAgent = $_SERVER['HTTP_USER_AGENT'];
     $uuid = \PHPAuth\Util::generateUuid();
     return new self($uuid, $userId, $userAgent, $ipAddress, $creationDate, $expiryDate, NULL, $isPersistent);
 }