-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Muhammet Şafak edited this page May 29, 2026
·
2 revisions
Welcome to the official documentation for initphp/sessions — a small,
framework-agnostic session manager that puts a fluent, exception-aware API in
front of PHP's native sessions, with pluggable save handlers so you can store
sessions wherever you like.
The package ships three building blocks:
| Type | Purpose |
|---|---|
Session |
The facade you call (Session::set(...), Session::start()). |
AbstractAdapter |
Base class for save handlers; implement read/write/destroy. |
AdapterInterface |
The contract — extends PHP's native SessionHandlerInterface. |
composer require initphp/sessionsuse InitPHP\Sessions\Session;
Session::createImmutable()
->start();
Session::set('username', 'admin')
->set('mail', 'admin@example.com');
echo Session::get('username', 'guest'); // 'admin'- New to the package? Read Installation, then Quick Start.
- Want the big picture? Read The Session Facade.
- Storing sessions somewhere specific? See Adapters and pick a backend.
- Building login? Read the Authentication recipe.
- Need a method signature? The API Reference lists every public member.
- Upgrading? Read the Migration Guide.
- A fluent facade over
$_SESSIONand thesession_*()lifecycle — readable reads, chainable writes, and predictable exceptions instead of raw warnings. - Six bundled adapters behind one interface: File, Redis, PDO (MySQL/PostgreSQL/SQLite), Cookie (encrypted, server-less), Memcache/Memcached, and MongoDB.
- A tiny extension point — write your own handler by extending
AbstractAdapter. - Drops in alongside plain
$_SESSION; it is a convenience layer, not a replacement.
| Adapter | Stores in | Requires | Built-in expiry |
|---|---|---|---|
| File | Files in a directory | — | via gc()
|
| Redis | Redis | ext-redis |
TTL |
| PDO | SQL database |
ext-pdo + driver |
via gc()
|
| Cookie | Encrypted client cookie |
initphp/encryption, ext-openssl
|
cookie lifetime |
| Memcache(d) | Memcache/Memcached |
ext-memcached or ext-memcache
|
TTL |
| MongoDB | MongoDB | ext-mongodb |
via gc()
|
- License: MIT
- Minimum PHP: 8.1 (tested on 8.1 – 8.4)
- Runtime dependencies: none (adapters pull in their own extensions)
-
Packagist:
initphp/sessions - Source: github.com/InitPHP/Sessions
- Issues: github.com/InitPHP/Sessions/issues
- Discussions: github.com/orgs/InitPHP/discussions
-
Security:
SECURITY.md
If something in this wiki is unclear, ambiguous, or wrong, please open an issue — documentation fixes are reviewed eagerly.
initphp/sessions · MIT License · part of the InitPHP family
Source · Issues · Discussions · Packagist · Contributing · Security Policy
Getting Started
Core Usage
Adapters
- Adapters Overview
- File Adapter
- Redis Adapter
- PDO Adapter
- Cookie Adapter
- Memcache / Memcached Adapter
- MongoDB Adapter
- Custom Adapters
Reference
Practical Guides
Migration & Help