nixphp / session
NixPHP Session Plugin for storing data across requests.
Installs: 23
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:nixphp-plugin
Requires
- php: >=8.3
- nixphp/framework: dev-main
Requires (Dev)
- phpunit/php-code-coverage: ^12.1
- phpunit/phpunit: ^12.1
This package is auto-updated.
Last update: 2025-05-31 21:10:51 UTC
README
nixphp/session
Simple session management for NixPHP — with flash message support built-in.
This plugin adds a lightweight, dependency-free session handler to your NixPHP app. It starts the session automatically and provides helpers for storing data across requests — including flash messages.
🧩 Part of the official NixPHP plugin collection. Install it when you need session persistence — and nothing else.
📦 Features
- ✅ Starts PHP sessions automatically
- ✅ Store/retrieve session data easily
- ✅ Flash message system for one-time notices
- ✅ No configuration needed
- ✅ PSR-11 container integration (
session()
)
📥 Installation
composer require nixphp/session
Once installed, the plugin is autoloaded and ready to use.
🚀 Usage
📌 Accessing the session
Use the global session()
helper to access the session storage:
session()->set('user_id', 42); $userId = session()->get('user_id');
To remove a key:
session()->forget('user_id');
✨ Flash messages
Use flash messages to store data for the next request only (e.g. after a redirect):
session()->flash('success', 'Profile updated.');
In the next request, access it using:
<?php if ($message = session()->get('success')): ?> <p class="success"><?= $message ?></p> <?php endif; ?>
The message is then automatically removed after it has been read.
🔍 Internals
- Automatically starts
session_start()
if it hasn't run yet. - Flash data is stored in a dedicated key and removed after access.
- Registers the
session()
helper and binds it in the service container.
✅ Requirements
nixphp/framework
>= 1.0
🛠 Optional Usage in Controllers
You can also access the session directly from the container:
$session = app()->container()->get('session');
But using the session()
helper is the recommended way.
📄 License
MIT License.