19 declare(strict_types=1);
34 private string $id =
'';
51 if (self::$instance) {
52 return self::$instance;
54 return self::$instance =
new self(
$logger);
68 public function init(): bool
70 if (session_status() === PHP_SESSION_ACTIVE) {
71 $this->
getLogger()->error(__METHOD__ .
' called with active session.');
78 $this->
setId(session_id());
83 $this->
getLogger()->debug(
'Resuming old session for user: ' . $user_id);
85 $this->expired = (bool)
ilSession::get(self::SESSION_AUTH_EXPIRED);
86 $this->authenticated = (bool)
ilSession::get(self::SESSION_AUTH_AUTHENTICATED);
90 $this->
getLogger()->debug(
'Started new session.');
92 $this->expired =
false;
93 $this->authenticated =
false;
111 $old_session_id = session_id();
112 session_regenerate_id(
true);
113 $this->
setId(session_id());
114 $this->
getLogger()->info(
'Session regenerate id: [' . substr($old_session_id, 0, 5) .
'] -> [' . substr($this->
getId(), 0, 5) .
']');
123 session_regenerate_id(
true);
143 $this->authenticated = $a_status;
144 $this->user_id = $a_user_id;
166 $this->expired = $a_status;
175 $this->user_id = $a_id;
206 protected function setId(
string $a_id): void
static get(string $a_var)
logout()
Logout user => stop session.
setUserId(int $a_id)
Set authenticated user id.
regenerateId()
Regenerate id.
isExpired()
Check if current is or was expired in last request.
isAuthenticated()
Check if session is authenticated.
static lookupExpireTime(string $a_session_id)
Lookup expire time for a specific session.
const SESSION_AUTH_AUTHENTICATED
const SESSION_AUTH_USER_ID
getUserId()
Get authenticated user id.
init()
Start auth session.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setExpired(bool $a_status)
Set session expired.
const SESSION_AUTH_EXPIRED
isValid()
Check if current session is valid (authenticated and not expired)
setAuthenticated(bool $a_status, int $a_user_id)
Set authenticated.
validateExpiration()
Check expired value of session.
static ilAuthSession $instance
static getInstance(\ilLogger $logger)
Get instance.
__construct(\ilLogger $logger)
static set(string $a_var, $a_val)
Set a value.
setId(string $a_id)
Set id.