composer require easy-session/easy-session
- Get instance of session
require_once './vendor/autoload.php';
use Easy\EasySession\Session;
$session = Session::getInstance();
- Start session
$session->start();
- Set value by key
$session->set('key', 'values');
- Get values from session by key
$session->get('key');
4.1 Get default value if key does not exists
$default = $session->get('not_existing_key', 'default value');
- Get all items
$session->all();
- Get item and remove it
$session->remove('key');
- Free(clear) all session variables
$session->clear();
- Clear all and destory session
$session->destroy();
- Get session id
$session->getId();
- Set from existing key
$session->setFromExistingKey('new_key', 'exis_key');
- Start session and set, get, remove velue
require_once './vendor/autoload.php';
use Easy\EasySession\Session;
$session = Session::getInstance();
$session->start(); // Start session
$session->set('user', ['name' => 'Ali', 'email' => 'test@gmail']); // setting data to session
$user = $session->get('user'); // getting user from sesion
echo '<pre>';
print_r($user);
// output: Array([name] => Ali [email] => test@gmail)
// not existing key
print_r($session->get('test'))
//output: NULL
// default value
print_r($session->get('test', 'default value'))
//output: default value
//Remove item from session
$session->remove('user');
// get item and remove it
$user = $session->get('user');
- Free all session variables and destroy
require_once './vendor/autoload.php';
use Easy\EasySession\Session;
$session = Session::getInstance();
$session->start(); // Start session
$session->set('user', ['name' => 'Ali', 'email' => 'test@gmail']); // setting data to session
$session->set('cart', ['product 1', 'product 2']);
echo count($this->all());
// output: 2
$session->isEmpty(); // return false session not empty
$session->clear(); // clear all session variables
$session->isEmpty(); // return true
// to destroy session
$session->destroy();