PHP code example of prog98rammer / php-session

1. Go to this page and download the library: Download prog98rammer/php-session library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

prog98rammer / php-session example snippets


#
use Prog98rammer\Session\Session;

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


$session = new Session($prefix);

$session = new Session('test_');

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

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

$sesssion->all();

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

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

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

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

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

$session->fromPrefix($prefix);

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



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

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


$sesssion->remove($key);

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

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

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

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

$session->destroy();