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:

TypePurpose
SegmentFacade in front of a single adapter. Pick the adapter via factory methods.
AdapterInterfaceStorage contract — depend on this in your services.
AbstractAdapterBase class with a default collective(). Most custom adapters extend this.
SessionAdapter$_SESSION-backed storage.
CookieAdapterSigned-cookie storage (JSON + HMAC-SHA256).
NullAdapterNull Object — accepts every operation, stores nothing.
CookieWriterInterfaceAbstraction over setcookie() so the cookie adapter is testable.
PermissionCase-insensitive named permission set.
composer require initphp/auth
useInitPHP\Auth\Permission;
useInitPHP\Auth\Segment;
session_start();
$auth = Segment::session('auth');
$auth->set('user_id', 42)->set('role', 'editor');
$perm = newPermission([$auth->get('role')]);
if ($perm->is('editor')) {
// do editor things
}

Start here

At a glance — adapter feature matrix

CapabilitySessionAdapterCookieAdapterNullAdapterCustom
Per-request lifetime✅ (until session ends)✅ (until expiry)n/a
Survives PHP restart⚠️ (if session save handler persists)n/adepends
Stateless serverdepends
Tamper-proof✅ (server-side)✅ (HMAC-SHA256)n/adepends
Capacitybounded by $_SESSIONbounded by cookie size (~4 KB)unlimited (no-op)depends
Testable without headersn/a✅ (CookieWriterInterface)depends
Atomic bulk write (collective())✅ (one $_SESSION write)✅ (one Set-Cookie)n/aimplements 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