Session
Session
Session class.
Sessions make use of the Hazaar\Cache\Adapter class but they create a unique session ID so stored data is not shared between user sessions. If you want to store data that can be shared then use the Hazaar\Cache\Adapter classes directly.
Properties
sessionName
private string $sessionName = 'hazaar-session'sessionId
public string $sessionIdsessionInit
private bool $sessionInitMethods
__construct
Session constructor.
public __construct(array $options, ?string $backend): voidInitializes a new session instance with the provided options and backend.
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array | |
$backend | string | The backend to use for session storage. Optional. |
set
Sets a session value for the specified key with an optional timeout.
public set(mixed $key, mixed $value, int $timeout): boolIf the session has not been initialized and the script is not running in CLI mode, this method will set a session cookie and mark the session as initialized. Then, it delegates the actual storage of the value to the parent implementation.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | mixed | the key under which the value will be stored in the session |
$value | mixed | the value to store in the session |
$timeout | int | Optional. The timeout for the session value in seconds. Defaults to 0 (no timeout). |
clear
Clears the current session data.
public clear(): voidCalls the parent clear method to remove all session data, and then checks if the session cookie matches the current session ID. If so, it deletes the session cookie by setting its expiration time in the past.
Generated by Hazaar API Doc Generator on Sun, 01 Mar 2026 09:22:25 +0000