Skip to content

A simple PHP session handler library with some extra features

License

Notifications You must be signed in to change notification settings

xenokore/xeno-session

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xeno Session

A simple PHP session handler library with some extra features.

Installation

composer require xenokore/session

Usage

Load the $_SESSION variable in the constructor:

$session = new Xenokore\Session\Session($_SESSION);

You can access it as an array as if you're working directly with $_SESSION:

$session['test'] = 'hello';

var_dump($session['test']); // string(4) "test"

unset($session['test']);

You can also use the get() and set() methods:

// "name" will not be found so the default fallback will be used
var_dump( $session->get('name', 'unknown') ); // string(7) "unknown"

$session->set('name', 'yani'),

echo $session->get('name', 'unknown'); // string(4) "yani"

Another feature of this library is to remember a variable once using once() and getOnce(). This behaves like FlashMessages and can be used to pass one-time data between requests:

$session->once('error', 'failed to login');

// On a different request:
$error = $session->getOnce('error', null);

if($error){
    var_dump($error); // string(15) "failed to login"
}

$error = $session->getOnce('error', null);

var_dump($error); // null

getOnce() instantly removes the one-time variable from the session. You can also use getAllOnce() to get all one-time variables.

About

A simple PHP session handler library with some extra features

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages