‪TYPO3CMS  11.5
TYPO3\CMS\Core\Session\UserSession Class Reference

Public Member Functions

string getIdentifier ()
 
int getUserId ()
 
int getLastUpdated ()
 
 set (string $key, $value)
 
bool hasData ()
 
mixed get (string $key)
 
array getData ()
 
 overrideData (array $data)
 
bool dataWasUpdated ()
 
bool isAnonymous ()
 
string getIpLock ()
 
bool isNew ()
 
bool isPermanent ()
 
bool needsUpdate ()
 
array toArray ()
 

Static Public Member Functions

static UserSession createFromRecord (string $id, array $record, bool $markAsNew=false)
 
static UserSession createNonFixated (string $identifier)
 

Protected Member Functions

 __construct (string $identifier, int $userId, int $lastUpdated, array $data=[])
 

Protected Attributes

const SESSION_UPDATE_GRACE_PERIOD = 61
 
string $identifier
 
int $userId
 
int $lastUpdated
 
array $data
 
bool $wasUpdated = false
 
string $ipLock = ''
 
bool $isNew = true
 
bool $isPermanent = false
 

Detailed Description

Represents all information about a user's session. A user session can be bound to a frontend / backend user, or an anonymous session based on session data stored in the session backend.

If a session is anonymous, it can be fixated by storing the session in the backend, but only if there is data in the session.

if a session is user-bound, it is automatically fixated.

The $isNew flag is meant to show that this user session object was not fetched from the session backend, but initialized in the first place by the current request.

The $data argument is to store any arbitrary data valid for the users' session.

A permanent session means that the client is not issued a session-based cookie but a time-based cookie. So the server-session survives the session of the browser.

Definition at line 38 of file UserSession.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Session\UserSession::__construct ( string  $identifier,
int  $userId,
int  $lastUpdated,
array  $data = [] 
)
protected

Member Function Documentation

◆ createFromRecord()

static UserSession TYPO3\CMS\Core\Session\UserSession::createFromRecord ( string  $id,
array  $record,
bool  $markAsNew = false 
)
static

◆ createNonFixated()

◆ dataWasUpdated()

bool TYPO3\CMS\Core\Session\UserSession::dataWasUpdated ( )

Check if session data was already updated

Returns
‪bool

Definition at line 160 of file UserSession.php.

References TYPO3\CMS\Core\Session\UserSession\$wasUpdated.

◆ get()

mixed TYPO3\CMS\Core\Session\UserSession::get ( string  $key)

Return the data for the given key or an NULL if the key does not exist

Parameters
string$key
Returns
‪mixed

Definition at line 124 of file UserSession.php.

Referenced by TYPO3\CMS\Core\Session\UserSessionManager\createSessionFromStorage(), and TYPO3\CMS\Core\Session\UserSessionManager\regenerateSession().

◆ getData()

array TYPO3\CMS\Core\Session\UserSession::getData ( )

Return the whole session data array.

Returns
‪array

Definition at line 134 of file UserSession.php.

References TYPO3\CMS\Core\Session\UserSession\$data.

◆ getIdentifier()

◆ getIpLock()

string TYPO3\CMS\Core\Session\UserSession::getIpLock ( )

Return the sessions ipLock state

Returns
‪string

Definition at line 181 of file UserSession.php.

References TYPO3\CMS\Core\Session\UserSession\$ipLock.

◆ getLastUpdated()

int TYPO3\CMS\Core\Session\UserSession::getLastUpdated ( )

Get the timestamp of the last session data update

Returns
‪int

Definition at line 83 of file UserSession.php.

References TYPO3\CMS\Core\Session\UserSession\$lastUpdated.

Referenced by TYPO3\CMS\Core\Session\UserSessionManager\hasExpired(), and TYPO3\CMS\Core\Session\UserSessionManager\willExpire().

◆ getUserId()

int TYPO3\CMS\Core\Session\UserSession::getUserId ( )

Get the user id (ID of the user record to whom the session belongs)

Returns
‪int

Definition at line 73 of file UserSession.php.

References TYPO3\CMS\Core\Session\UserSession\$userId.

◆ hasData()

bool TYPO3\CMS\Core\Session\UserSession::hasData ( )

Check whether the session has data

Returns
‪bool

Definition at line 113 of file UserSession.php.

◆ isAnonymous()

bool TYPO3\CMS\Core\Session\UserSession::isAnonymous ( )

Check if the user session is an anonymous one. This means, the session does not belong to a logged-in user.

Returns
‪bool

Definition at line 171 of file UserSession.php.

◆ isNew()

bool TYPO3\CMS\Core\Session\UserSession::isNew ( )

Check whether the session was marked as new on creation

Returns
‪bool

Definition at line 191 of file UserSession.php.

References TYPO3\CMS\Core\Session\UserSession\$isNew.

Referenced by TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\checkAuthentication(), and TYPO3\CMS\Core\Session\UserSessionManager\recreateUserSession().

◆ isPermanent()

bool TYPO3\CMS\Core\Session\UserSession::isPermanent ( )

Check whether the session was marked as permanent on creation

Returns
‪bool

Definition at line 201 of file UserSession.php.

References TYPO3\CMS\Core\Session\UserSession\$isPermanent.

Referenced by TYPO3\CMS\Core\Session\UserSession\toArray().

◆ needsUpdate()

bool TYPO3\CMS\Core\Session\UserSession::needsUpdate ( )

Use a gracetime-value to avoid updating a session-record too often

Returns
‪bool

Definition at line 211 of file UserSession.php.

References $GLOBALS, and TYPO3\CMS\Core\Session\UserSession\SESSION_UPDATE_GRACE_PERIOD.

Referenced by TYPO3\CMS\Core\Session\UserSessionManager\updateSessionTimestamp().

◆ overrideData()

TYPO3\CMS\Core\Session\UserSession::overrideData ( array  $data)

Override the whole $data. Can be used to e.g. preserve session data on login or to remove session data by providing an empty array.

Parameters
array$data

Definition at line 145 of file UserSession.php.

References TYPO3\CMS\Core\Session\UserSession\$data.

◆ set()

TYPO3\CMS\Core\Session\UserSession::set ( string  $key,
  $value 
)

Set / update a data value for a given key. Throws an exception if the given key is empty.

Parameters
string$key‪The key whose value should be updated
mixed$value‪The value or NULL to unset the key

Definition at line 95 of file UserSession.php.

◆ toArray()

array TYPO3\CMS\Core\Session\UserSession::toArray ( )

Member Data Documentation

◆ $data

◆ $identifier

◆ $ipLock

string TYPO3\CMS\Core\Session\UserSession::$ipLock = ''
protected

Definition at line 46 of file UserSession.php.

Referenced by TYPO3\CMS\Core\Session\UserSession\getIpLock().

◆ $isNew

bool TYPO3\CMS\Core\Session\UserSession::$isNew = true
protected

Definition at line 47 of file UserSession.php.

Referenced by TYPO3\CMS\Core\Session\UserSession\isNew().

◆ $isPermanent

bool TYPO3\CMS\Core\Session\UserSession::$isPermanent = false
protected

Definition at line 48 of file UserSession.php.

Referenced by TYPO3\CMS\Core\Session\UserSession\isPermanent().

◆ $lastUpdated

int TYPO3\CMS\Core\Session\UserSession::$lastUpdated
protected

◆ $userId

int TYPO3\CMS\Core\Session\UserSession::$userId
protected

◆ $wasUpdated

bool TYPO3\CMS\Core\Session\UserSession::$wasUpdated = false
protected

Definition at line 45 of file UserSession.php.

Referenced by TYPO3\CMS\Core\Session\UserSession\dataWasUpdated().

◆ SESSION_UPDATE_GRACE_PERIOD

const TYPO3\CMS\Core\Session\UserSession::SESSION_UPDATE_GRACE_PERIOD = 61
protected

Definition at line 40 of file UserSession.php.

Referenced by TYPO3\CMS\Core\Session\UserSession\needsUpdate().