Since: 5.4

class SessionHandler implements SessionHandlerInterface, SessionIdInterface (View source)

SessionHandler a special class that can be used to expose the current internal PHP session save handler by inheritance. There are six methods which wrap the six internal session save handler callbacks (open, close, read, write, destroy and gc).

By default, this class will wrap whatever internal save handler is set as as defined by the session.save_handler configuration directive which is usually files by default. Other internal session save handlers are provided by PHP extensions such as SQLite (as sqlite), Memcache (as memcache), and Memcached (as memcached).

Methods

bool
close()

Close the session

string
create_sid()

Return a new session ID

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.

string create_sid()

Since: 5.5.1

Return a new session ID

Return Value

string

The new session ID. Note that 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.