Class yii\web\SessionHandler

Inheritanceyii\web\SessionHandler
ImplementsSessionHandlerInterface
Available since version2.0.52
Source Code https://github.com/yiisoft/yii2/blob/master/framework/web/SessionHandler.php

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

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

Method Details

Hide inherited methods

__construct() public method
public __construct( yii\web\Session $session ): mixed
$session yii\web\Session

                public function __construct(Session $session)
{
    $this->_session = $session;
}

            
close() public method
public close( ): boolean

                public function close(): bool
{
    return $this->_session->closeSession();
}

            
create_sid() public method (available since version 2.0.56)

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;
}

            
destroy() public method
public destroy( mixed $id ): boolean
$id mixed

                public function destroy($id): bool
{
    return $this->_session->destroySession($id);
}

            
gc() public method
public gc( mixed $max_lifetime ): mixed
$max_lifetime mixed

                #[\ReturnTypeWillChange]
public function gc($max_lifetime)
{
    return $this->_session->gcSession($max_lifetime);
}

            
open() public method
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);
}

            
read() public method
public read( mixed $id ): mixed
$id mixed

                #[\ReturnTypeWillChange]
public function read($id)
{
    return $this->_session->readSession($id);
}

            
validateId() public method (available since version 2.0.56)

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);
}

            
write() public method
public write( mixed $id, mixed $data ): boolean
$id mixed
$data mixed

                public function write($id, $data): bool
{
    return $this->_session->writeSession($id, $data);
}