// Store user data after login
Session::set('user_id', $user->id);
Session::set('user_role', $user->role);
Session::set('remember_token', $token, cookie: true); // also writes a cookie
// Read
$userId = Session::get('user_id');
// Guard a controller method
if (!Session::isExists('user_id')) {
Url::redirect(SITEURL . 'login/');
exit;
}
// Nested key (e.g. cart)
Session::setKey('cart', $productId, ['qty' => 2, 'price' => 9.99]);
$cart = Session::get('cart'); // ['product-1' => ['qty' => 2, ...]]
// Destroy on logout
Session::endSession();
Url::redirect(SITEURL);
Framework Docs
Session
Session
The Session class provides a static API for reading and writing PHP sessions, cookies, and flash data. Sessions are namespaced with INSTALL_KEY to prevent collisions between multiple applications on the same server.
Namespace: Wojo\Core\Session
Session Methods
| Method | Signature | Description |
|---|---|---|
| set() | static set(string $name, mixed $value, bool $cookie = false): void |
Write a session value (and optionally a cookie) |
| get() | static get(string $name, mixed $default = null): mixed |
Read a session value |
| setKey() | static setKey(string $name, string $key, mixed $value): void |
Write a nested key inside a session array |
| remove() | static remove(string $name): void |
Delete a session key |
| isExists() | static isExists(string $name): bool |
Check if a session key exists and is non-empty |
| endSession() | static endSession(): void |
Destroy the session and clear all cookies |
| getSessionName() | static getSessionName(): string |
Return the namespaced session name |
| getTimeout() | static getTimeout(): int |
Return the configured session lifetime in seconds |
Cookie Methods
| Method | Signature | Description |
|---|---|---|
| getCookie() | static getCookie(string $name): mixed |
Read a cookie value |
| removeCookie() | static removeCookie(string $name): void |
Expire and remove a cookie |
| cookieExists() | static cookieExists(string $name, mixed $value = null): bool |
Check if a cookie exists (and optionally matches a value) |
CAPTCHA Helpers
| Method | Description |
|---|---|
| captcha(): string | Generate and store a 6-char alphanumeric CAPTCHA token in session; returns the token |
| captchaAlt(): string | Alternative CAPTCHA generator (numeric only) |