Skip to content
Muhammet Şafak edited this page May 29, 2026 · 2 revisions

InitPHP Sessions — Wiki

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/sessions
use InitPHP\Sessions\Session;

Session::createImmutable()
    ->start();

Session::set('username', 'admin')
    ->set('mail', 'admin@example.com');

echo Session::get('username', 'guest'); // 'admin'

Start here

What it does

  • A fluent facade over $_SESSION and the session_*() 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 cheat-sheet

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()

Package metadata

If something in this wiki is unclear, ambiguous, or wrong, please open an issue — documentation fixes are reviewed eagerly.

Clone this wiki locally