-
Notifications
You must be signed in to change notification settings - Fork 2
Session
Pair\Models\Session is the ActiveRecord model for persisted user sessions.
It also provides static helpers for PHP session values.
Pair v4 configures native PHP sessions with an app-scoped cookie name derived from APP_NAME, rather than relying on the shared PHPSESSID default. This prevents local applications on the same host from reading or overwriting each other's PHP session cookie.
current(): ?Sessiondestroy(): voidextendTimeout()isExpired(int $sessionTime): boolcleanOlderThan(int $sessionTime): void
getUser(): ?UsersetUser(User $user): voidgetFormerUser(): ?UsersetFormerUser(User $formerUser)hasFormerUser(): bool
get(string $key): mixedset(string $key, mixed $value): voidhas(string $key): boolunset(string $key): void
Before Pair starts a PHP session, Application::configureNativeSessionCookie() sets:
- an app-specific cookie name such as
PairApplicationSession - a cookie path derived from
URL_PATH SameSite=LaxHttpOnly=true-
secure=trueon HTTPS or trusted proxy HTTPS requests
Session::destroy() uses the same cookie name and path when deleting the browser cookie.
After upgrading to this behavior, existing PHPSESSID browser sessions are not reused. Users may need to log in once per application.
$session = \Pair\Models\Session::current();
if ($session && $session->isExpired(60)) {
\Pair\Models\Session::destroy();
}Set/get session data:
\Pair\Models\Session::set('csrf', $token);
$csrf = \Pair\Models\Session::get('csrf');See also: User, Application, Configuration-file.