Skip to content

khalidsheet/session-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Session Manager

Allows you to deal with Session in php


Installation

#include your file
include './to/path/session-manager.php';

use Prog98rammer\Session\Session;

// start the session.
$session = new Session();

Usage

-- Basic Usage

Set the sessoin prefix

There are two ways to set the prefix

-- First One

$session = new Session($prefix);

-- Example

$session = new Session('test_');

Second way

$session = new Session;
$session->prefix('test_')->set('name', 'khalid'); // it will set the session as "test_name"

Get the session prefix

$sesssion->getPrefix(); // will return the session prefix

Get all session keys

$sesssion->all();

Add new session

// store the new session
$session->set($key, $value);

// for Example
$session->set('name', 'John');

Add more than one session by Chaining method

$session->set('name', 'Khalid')
        ->set('age', 19)
        ->set('country', 'Iraq')
        ->set('city', 'Baghdad');

Add more than one session by providing an array

$session->set([
    'name' => 'khalid',
    'age' => 19,
    'location' => [
        'country' => 'iraq',
        'city' => 'baghdad'
    ]
]);

Get one session by key

$sesssion->get($key); // will use the default prefix.

Get All Session by spicefic prefix

$session->fromPrefix($prefix);

#example
$session->fromPrefix('test'); // returns an array of all session that have a "test" prefix

Check if the session exists!

Session::has($key); // returns True or False

#example
if(Session::has('is_loggin')) {
   // do something
} else {
   // do something else
}

Remove Session by key

$sesssion->remove($key);

by chaining method

$session->remove('name')
        ->remove('age')
        ->remove('location');

by providing an array of keys

$session->remove([
    'name', 'age', 'location'
]);

or just like this

$session->remove('name', 'age', 'location');

Get the session id

$sesssion->id(); // will return the id of the session.

Regenerate the session id

$sesssion->regenerate_id(); // will return the id of the session.

if you like to remove all session at one

$session->destroy();