SessionHandler
API reference › yii › web › SessionHandler
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.
Methods
Section titled “Methods”| Method | Description | Defined 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 |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(yii\web\Session $session)Parameters
| Parameter | Type | Description |
|---|---|---|
$session | Session |
create_sid()
Section titled “create_sid() ”public function create_sid(): stringReturns 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
destroy()
Section titled “destroy() ”public function destroy(mixed $id): boolParameters
| Parameter | Type | Description |
|---|---|---|
$id | mixed |
Returns
bool
public function gc(mixed $max_lifetime): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$max_lifetime | mixed |
Returns
mixed
open()
Section titled “open() ”public function open(mixed $path, mixed $name): boolParameters
| Parameter | Type | Description |
|---|---|---|
$path | mixed | |
$name | mixed |
Returns
bool
read()
Section titled “read() ”public function read(mixed $id): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$id | mixed |
Returns
mixed
validateId()
Section titled “validateId() ”public function validateId(string $id): boolReturns 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
| Parameter | Type | Description |
|---|---|---|
$id | string | The session ID |
Returns
bool: Whether the session exists
Since
2.0.56
write()
Section titled “write() ”public function write(mixed $id, mixed $data): boolParameters
| Parameter | Type | Description |
|---|---|---|
$id | mixed | |
$data | mixed |
Returns
bool