Session
in package
implements
SessionHandlerInterface
Implementation of PHP's session API.
What it does:
- it handles the session data in the database (more scalable.)
- it uses the databaseSession_lifetime setting for garbage collection.
- the custom session handler is set by Session::load().
Table of Contents
Interfaces
- SessionHandlerInterface
Methods
- close() : bool
- Closes the session.
- destroy() : bool
- Destroys a session.
- gc() : int|false
- Cleans up old sessions.
- load() : void
- Attempt to start the session, unless it already has been.
- open() : bool
- Initializes the session.
- read() : string
- Read session data.
- write() : bool
- Writes session data.
Methods
close()
Closes the session.
public
close() : bool
Return values
bool —Always returns true.
destroy()
Destroys a session.
public
destroy(string $session_id) : bool
Parameters
- $session_id : string
-
The session ID.
Return values
bool —Whether the session was successfully destroyed.
gc()
Cleans up old sessions.
public
gc(int $max_lifetime) : int|false
Parameters
- $max_lifetime : int
-
Sessions that have not updated for the last $max_lifetime seconds will be removed.
Return values
int|false —The number of deleted sessions, or false on failure.
load()
Attempt to start the session, unless it already has been.
public
static load() : void
open()
Initializes the session.
public
open(string $path, string $name) : bool
Parameters
- $path : string
-
The path to save the session to.
- $name : string
-
The name of the session.
Return values
bool —Always returns true.
read()
Read session data.
public
read(string $session_id) : string
Note: The PHP manual says to return false if no record was found, but doing so causes errors on some versions of PHP when the user logs out. Returning an empty string works for all versions.
Parameters
- $session_id : string
-
The session ID.
Return values
string —The session data.
write()
Writes session data.
public
write(string $session_id, string $data) : bool
Parameters
- $session_id : string
-
The session ID.
- $data : string
-
The data to write to the session.
Return values
bool —Whether the info was successfully written.