Every method below is callable statically (Session::get(...)) or on the
instance returned by createImmutable(). Value methods are delegated to
GetterSetter; lifecycle methods to Manager.
Initialises the facade and returns an instance for chaining. Call it once per
request. Passing an adapter registers it as the save handler on start().
Session::createImmutable($adapter)->start();These operate on $_SESSION and are null-safe: before the session is started,
reads return their defaults rather than erroring.
Session::has('user'); // true / falseStores a value; returns the GetterSetter for chaining.
Session::set('a', 1)->set('b', 2);Returns the stored value, or $default when the key is absent. A stored null
is returned as-is (not replaced by the default).
Session::get('user', 'guest');Stores a value and returns the value (not $this), handy in expressions.
$token = Session::push('csrf', bin2hex(random_bytes(16)));Returns the value and removes the key — useful for one-shot "flash" data.
$notice = Session::pull('flash', null);Removes one or more keys. delete() is an alias of remove().
Session::remove('a', 'b');Returns the entire session payload.
foreach (Session::all() as $key => $value) { /* ... */ }Bulk-writes an associative array. Only string keys are written; numeric keys
are skipped. With $reset = true the session is replaced rather than merged.
Session::setAssoc(['user' => 'ada', 'role' => 'admin']);
Session::setAssoc(['only' => 'this'], true); // replaces everythingRegisters the adapter (if any) and starts the session. $options are forwarded
to session_start().
Session::start(['cookie_lifetime' => 3600]);if (!Session::isStarted()) {
Session::start();
}Read or set the session name. Call setName() before start().
Session::setName('APPSESSID');
echo Session::getName(); // "APPSESSID"Read or set the session id. Call setID() before start(). setID() returns
whether the id was accepted.
Issues a fresh session id — call it after a privilege change (e.g. login) to prevent fixation.
Session::regenerateId(true);Clear all session variables. Both require an active session and throw
SessionException otherwise. flush() is an alias of unset().
Session::flush();Destroys the session entirely.
Session::destroy();