spiral/session
Secure session management for PHP using native handlers, focused on safety and integrity. Part of the Spiral ecosystem, with framework integration available via the Spiral Framework bundle and full docs at spiral.dev. MIT licensed.
composer require spiral/sessionconfig/bundles.php:
Spiral\Session\Binder::class,
config/session.php (e.g., driver, lifetime, cookie name). Default driver is files, but supports array, cookie, redis, etc.\Spiral\Session\SessionInterface into controllers or middleware and use $session->set('key', $value) / $session->get('key').$session->setFlash('notice', 'Saved!') → retrieve next request with $session->getFlash('notice').SessionInterface to manage user-specific state (e.g., shopping cart, preferences):
public function store(SessionInterface $session): Response
{
$session->set('cart.items', [...]);
return $this->response->redirect('/cart');
}
$session->setFlash('success', 'Profile updated!');
return $this->redirect->to('profile');
$session->start();
// ... handle request
$session->commit(); // persists changes
\Spiral\Session\StorageInterface to support databases (e.g.,PDO, Doctrine DBAL), Redis, or custom backends—swap via config driver.cookie driver, remember the 4KB limit per cookie and avoid sensitive data (not encrypted by default).session_start() is not called automatically — call $session->start() explicitly (or rely on Binder middleware if used).start()), avoid long-running operations while holding a session lock. Use $session->close() early if no more writes needed.array driver in tests to isolate sessions per test (no file cleanup required).$session->has('key') or use $session->get('key', $default).SessionBinder runs before any middleware/controller that relies on session data.How can I help you explore Laravel packages today?