Skip to content
PHP Ecosystem
Explore

SessionHandler

API reference › yii › web › SessionHandler

classyii\web\SessionHandler
ImplementsSessionHandlerInterface
Since2.0.52
Sourceframework/web/SessionHandler.php

SessionHandler implements an SessionHandlerInterface for handling Session with custom session storage.

PHP detects create_sid() and validateId() by name, without the class implementing SessionIdInterface or SessionUpdateTimestampHandlerInterface.

MethodDescriptionDefined by
__construct()SessionHandler
close()SessionHandler
create_sid()Returns a new session ID created by createSessionId().SessionHandler
destroy()SessionHandler
gc()SessionHandler
open()SessionHandler
read()SessionHandler
validateId()Returns whether a session with the given ID exists.SessionHandler
write()SessionHandler
public function __construct(yii\web\Session $session)

Parameters

ParameterTypeDescription
$sessionSession
public function close(): bool

Returns

bool

public function create_sid(): string

Returns a new session ID created by createSessionId().

The ID is remembered until open(), so that validateId() reports it as missing when PHP checks it for collisions.

Returns

string: The new session ID

Since

2.0.56

public function destroy(mixed $id): bool

Parameters

ParameterTypeDescription
$idmixed

Returns

bool

public function gc(mixed $max_lifetime): mixed

Parameters

ParameterTypeDescription
$max_lifetimemixed

Returns

mixed

public function open(mixed $path, mixed $name): bool

Parameters

ParameterTypeDescription
$pathmixed
$namemixed

Returns

bool

public function read(mixed $id): mixed

Parameters

ParameterTypeDescription
$idmixed

Returns

mixed

public function validateId(string $id): bool

Returns whether a session with the given ID exists.

PHP calls this method for the ID supplied by the client when session.use_strict_mode is enabled, and for the ID returned by create_sid() to detect collisions: in session_regenerate_id() when strict mode is enabled, and in session_create_id() regardless of it. The ID returned by the last create_sid() call is reported as missing without consulting the storage, as createSessionId() must return IDs that do not collide; any other ID is checked through sessionIdExists().

Parameters

ParameterTypeDescription
$idstringThe session ID

Returns

bool: Whether the session exists

Since

2.0.56

public function write(mixed $id, mixed $data): bool

Parameters

ParameterTypeDescription
$idmixed
$datamixed

Returns

bool