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

InitPHP Auth — Wiki

Welcome to the official documentation for initphp/auth — a small PHP 8 authentication & authorization library with pluggable storage adapters (session, signed cookie, custom) and a tiny case-insensitive permission set.

The package ships these public types:

Type Purpose
Segment Facade in front of a single adapter. Pick the adapter via factory methods.
AdapterInterface Storage contract — depend on this in your services.
AbstractAdapter Base class with a default collective(). Most custom adapters extend this.
SessionAdapter $_SESSION-backed storage.
CookieAdapter Signed-cookie storage (JSON + HMAC-SHA256).
NullAdapter Null Object — accepts every operation, stores nothing.
CookieWriterInterface Abstraction over setcookie() so the cookie adapter is testable.
Permission Case-insensitive named permission set.
composer require initphp/auth
use InitPHP\Auth\Permission;
use InitPHP\Auth\Segment;

session_start();

$auth = Segment::session('auth');
$auth->set('user_id', 42)->set('role', 'editor');

$perm = new Permission([$auth->get('role')]);
if ($perm->is('editor')) {
    // do editor things
}

Start here

At a glance — adapter feature matrix

Capability SessionAdapter CookieAdapter NullAdapter Custom
Per-request lifetime ✅ (until session ends) ✅ (until expiry) n/a
Survives PHP restart ⚠️ (if session save handler persists) n/a depends
Stateless server depends
Tamper-proof ✅ (server-side) ✅ (HMAC-SHA256) n/a depends
Capacity bounded by $_SESSION bounded by cookie size (~4 KB) unlimited (no-op) depends
Testable without headers n/a ✅ (CookieWriterInterface) depends
Atomic bulk write (collective()) ✅ (one $_SESSION write) ✅ (one Set-Cookie) n/a implements default

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