prog98rammer/php-session

A PHP Session Class

1.0 2018-04-03 08:48 UTC

This package is not auto-updated.

Last update: 2024-04-18 14:19:59 UTC


README

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();