class Session

Provides access to session sections as well as session settings and management methods.

Constants

private DefaultFileLifetime

Default server-side idle timeout

private SecurityOptions

Properties

$onStart
$onBeforeWrite

Methods

__construct(IRequest $request, IResponse $response)

No description

void
start()

Starts and initializes session data.

void
autoStart(bool $forWrite)

No description

__destruct()

No description

bool
isStarted()

Checks whether the session has been started.

void
close()

Ends the current session and store session data.

void
destroy()

Destroys all data registered to a session.

bool
exists()

Does session exist for the current request?

void
regenerateId()

Regenerates the session ID.

string
getId()

Returns the current session ID. Avoid relying on the value - it may change between requests.

setName(string $name)

Sets the session name.

string
getName()

Gets the session name.

getSection(string $section, string $class = SessionSection::class)

Returns specified session section.

bool
hasSection(string $section)

Checks if a session section exist and is not empty.

array
getSectionNames()

Returns the names of all existing session sections.

setOptions(array $options)

Sets session options.

array
getOptions()

Returns all session options.

setExpiration(string|null $expire)

Sets the session lifetime as a time string (e.g. '20 minutes'), or null to revert to the default (a 3-hour server-side idle timeout; the session cookie itself is kept by the browser per its own policy).

setCookieParameters(string $path, string|null $domain = null, bool|null $secure = null, SameSite|string|null $sameSite = null)

Sets the session cookie parameters.

setSavePath(string $path)

Sets path of the directory used to save session data.

setHandler(SessionHandlerInterface $handler)

Sets user session handler.

Details

at line 53
__construct(IRequest $request, IResponse $response)

No description

Parameters

IRequest $request
IResponse $response

at line 67
void start()

Starts and initializes session data.

Return Value

void

Exceptions

InvalidStateException

at line 123
void autoStart(bool $forWrite)

internal  
 

No description

Parameters

bool $forWrite

Return Value

void

at line 179
__destruct()

No description

at line 188
bool isStarted()

Checks whether the session has been started.

Return Value

bool

at line 197
void close()

Ends the current session and store session data.

Return Value

void

at line 210
void destroy()

Destroys all data registered to a session.

Return Value

void

at line 230
bool exists()

Does session exist for the current request?

Return Value

bool

at line 241
void regenerateId()

Regenerates the session ID.

Return Value

void

Exceptions

InvalidStateException

at line 264
string getId()

Returns the current session ID. Avoid relying on the value - it may change between requests.

Return Value

string

at line 273
Session setName(string $name)

Sets the session name.

Parameters

string $name

Return Value

Session

at line 289
string getName()

Gets the session name.

Return Value

string

at line 304
SessionSection getSection(string $section, string $class = SessionSection::class)

Returns specified session section.

Parameters

string $section
string $class

Return Value

SessionSection

at line 313
bool hasSection(string $section)

Checks if a session section exist and is not empty.

Parameters

string $section

Return Value

bool

at line 327
array getSectionNames()

Returns the names of all existing session sections.

Return Value

array

at line 380
Session setOptions(array $options)

Sets session options.

Parameters

array $options

Return Value

Session

Exceptions

NotSupportedException
InvalidStateException

at line 429
array getOptions()

Returns all session options.

Return Value

array

at line 486
Session setExpiration(string|null $expire)

Sets the session lifetime as a time string (e.g. '20 minutes'), or null to revert to the default (a 3-hour server-side idle timeout; the session cookie itself is kept by the browser per its own policy).

Parameters

string|null $expire

Return Value

Session

at line 508
Session setCookieParameters(string $path, string|null $domain = null, bool|null $secure = null, SameSite|string|null $sameSite = null)

Sets the session cookie parameters.

Parameters

string $path
string|null $domain
bool|null $secure
SameSite|string|null $sameSite

Return Value

Session

at line 527
Session setSavePath(string $path)

Sets path of the directory used to save session data.

Parameters

string $path

Return Value

Session

at line 538
Session setHandler(SessionHandlerInterface $handler)

Sets user session handler.

Parameters

SessionHandlerInterface $handler

Return Value

Session