Repository navigation
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.
Home · Setup · Configuration
Build with Pair 4
- Generator
- Controllers and responses
- Read models
- ActiveRecord and queries
- Forms and validation
- PairUI.js and HTML fragments
APIs and authentication
- API guide and CRUD
- Middleware and rate limits
- Users, sessions, and ACL
- Passkeys and social login
- Native mobile setup
Integrate and operate
- Integrations
- Runtime extensions and adapter keys
- Cache and cache stores
- Logs and observability
- PWA and push
- Packages and distribution
- Upgrade to v4