Class yii\web\SessionHandler
| Inheritance | yii\ |
|---|---|
| Implements | SessionHandlerInterface |
| Available since version | 2.0.52 |
| Source Code | https://github.com/yiisoft/yii2/blob/master/framework/web/SessionHandler.php |
SessionHandler implements an SessionHandlerInterface for handling yii\
PHP detects create_sid() and validateId() by name, without the class implementing SessionIdInterface
or SessionUpdateTimestampHandlerInterface.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | yii\ |
|
| close() | yii\ |
|
| create_sid() | Returns a new session ID created by Session::createSessionId(). | yii\ |
| destroy() | yii\ |
|
| gc() | yii\ |
|
| open() | yii\ |
|
| read() | yii\ |
|
| validateId() | Returns whether a session with the given ID exists. | yii\ |
| write() | yii\ |
Method Details
| public __construct( yii\ | ||
| $session | yii\ |
|
public function __construct(Session $session)
{
$this->_session = $session;
}
Returns a new session ID created by Session::createSessionId().
The ID is remembered until open(), so that validateId() reports it as missing when PHP checks it for collisions.
| public create_sid( ): string | ||
| return | string |
The new session ID |
|---|---|---|
public function create_sid(): string
{
$this->_createdId = $this->_session->createSessionId();
return $this->_createdId;
}
| public destroy( mixed $id ): boolean | ||
| $id | mixed | |
public function destroy($id): bool
{
return $this->_session->destroySession($id);
}
| public gc( mixed $max_lifetime ): mixed | ||
| $max_lifetime | mixed | |
#[\ReturnTypeWillChange]
public function gc($max_lifetime)
{
return $this->_session->gcSession($max_lifetime);
}
| public open( mixed $path, mixed $name ): boolean | ||
| $path | mixed | |
| $name | mixed | |
public function open($path, $name): bool
{
$this->_createdId = null;
return $this->_session->openSession($path, $name);
}
| public read( mixed $id ): mixed | ||
| $id | mixed | |
#[\ReturnTypeWillChange]
public function read($id)
{
return $this->_session->readSession($id);
}
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 Session::createSessionId() must return IDs that do not collide;
any other ID is checked through Session::sessionIdExists().
| public validateId( string $id ): boolean | ||
| $id | string |
The session ID |
| return | boolean |
Whether the session exists |
|---|---|---|
public function validateId($id): bool
{
if ($id === $this->_createdId) {
return false;
}
return $this->_session->sessionIdExists($id);
}