Since: 5.4

interface SessionHandlerInterface (View source)

SessionHandlerInterface is an interface which defines a prototype for creating a custom session handler.

In order to pass a custom session handler to session_set_save_handler() using its OOP invocation, the class must implement this interface.

Methods

bool
close()

Close the session

bool
destroy(string $id)

Destroy a session

int|false
gc(int $max_lifetime)

Cleanup old sessions

bool
open(string $path, string $name)

Initialize session

string|false
read(string $id)

Read session data

bool
write(string $id, string $data)

Write session data

Details

bool close()

Since: 5.4

Close the session

Return Value

bool

The return value (usually TRUE on success, FALSE on failure). Note this value is returned internally to PHP for processing.

bool destroy(string $id)

Since: 5.4

Destroy a session

Parameters

string $id

The session ID being destroyed.

Return Value

bool

The return value (usually TRUE on success, FALSE on failure). Note this value is returned internally to PHP for processing.

int|false gc(int $max_lifetime)

Since: 5.4

Cleanup old sessions

Parameters

int $max_lifetime

Sessions that have not updated for the last maxlifetime seconds will be removed.

Return Value

int|false

Returns the number of deleted sessions on success, or false on failure. Prior to PHP version 7.1, the function returned true on success. Note this value is returned internally to PHP for processing.

bool open(string $path, string $name)

Since: 5.4

Initialize session

Parameters

string $path

The path where to store/retrieve the session.

string $name

The session name.

Return Value

bool

The return value (usually TRUE on success, FALSE on failure). Note this value is returned internally to PHP for processing.

string|false read(string $id)

Since: 5.4

Read session data

Parameters

string $id

The session id to read data for.

Return Value

string|false

Returns an encoded string of the read data. If nothing was read, it must return false. Note this value is returned internally to PHP for processing.

bool write(string $id, string $data)

Since: 5.4

Write session data

Parameters

string $id

The session id.

string $data

The encoded session data. This data is the result of the PHP internally encoding the $_SESSION superglobal to a serialized string and passing it as this parameter. Please note sessions use an alternative serialization method.

Return Value

bool

The return value (usually TRUE on success, FALSE on failure). Note this value is returned internally to PHP for processing.