birkanoruc / session-helper
A PHP helper class for managing sessions with features like flash data, session destruction, and more.
v1.0.0
2024-10-10 10:20 UTC
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^10.0
README
Session Helper is a simple PHP class that provides easy methods to manage sessions, including flash messages, session destruction, and more.
Installation
To install via Composer, run the following command:
composer require birkanoruc/session-helper
Usage
Starting a Session
Make sure to start the session in your application before using the session helper:
Birkanoruc\SessionHelper\Session::start();
or
session_start();
Check if a Session Key Exists
use Birkanoruc\SessionHelper\Session; if (Session::has('user_id')) { // Do something }
Store a Session Value
Session::put('user_id', 123);
Retrieve a Session Value
$userId = Session::get('user_id');
Flash Data (temporary session data)
Session::flash('message', 'User created successfully!');
Clear Flash Data
Session::unflash();
Destroy a Session
Session::destroy();
Testing
To run the tests for this library, you need to have PHPUnit installed. Follow these steps:
-
Make sure you have installed the required dependencies:
composer install
-
Run the tests using PHPUnit:
vendor/bin/phpunit tests
License
This project is licensed under the MIT License.