PHP code example of hub20xx / session

1. Go to this page and download the library: Download hub20xx/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/ */

    

hub20xx / session example snippets


// Forget about session_start():
//   - current session left alone if present
//   - new session started if no session present
$session = new \hub20xxx\Session\Session;

// Checking the existence of a session variable
$session->exists('variable'); // returns a boolean

// Setting session variables
$session->set('myString', 'stringy string');
$session->set('myArray', ['key' => 'value', 'otherKey' => 'otherValue']);
$session->set('myClass', new StdClass);

// Getting values of session variables
$mySessionString = $session->get('myString');
$mySessionArray = $session->get('myArray');
$mySessionClass = $session->get('myClass');

// Deleting session variables
$session->delete('myString');
$session->delete('myArray');
$session->delete('myClass');

// Flashing session variables
// 1. Setting the session variable (you can use the set method as well)
$session->flash('myFlashString', 'stringy string');
$session->flash('myFlashArray', ['key' => 'value', 'otherKey' => 'otherValue']);
$session->flash('myFlashClass', new StdClass);

// 2. Getting values of session variables and deleting them
$myFlashString = $session->flash('myFlashString');
$myFlashArray = $session->flash('myFlashArray');
$myFlashClass = $session->flash('myFlashClass');