PHP code example of phossa2 / session

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

    

phossa2 / session example snippets


use Phossa2\Session\Session;
use Phossa2\Session\Carton;

// start a 'global' session
$sessGlobal = new Session('global');

// set 'global' session as the default
Carton::setDefaultSession($sessGlobal);

// start another 'private' session at the same time
$sessPrivate = new Session('private');

// a box using default session 'global'
$boxGlobal = new Carton();

// global counter
++$boxGlobal['counter'];

// another box named 'toy' using the private session
$boxPrivate = new Carton('toy', $sessPrivate);

// private counter
++$boxPrivate['counter'];

  // use a cookie named 'one'
  $sessOne = new Session('one');

  // use a cookie named 'two'
  $sessTwo = new Session('two');
  

  // box 1
  $boxOne = new Carton('one', $sessPrivate);
  $boxOne['drone'] = 2;

  // box 2
  $boxTwo = new Carton('two', $sessPrivate);
  $boxTwo['drone'] = 1;
  

    use Phossa2\Session\Handler\StorageHandler;

    // inject a phossa2/storage handler
    $session->setHandler(new StorageHandler($storage, '/tmp/session'));
    

    use My\Own\HeaderDriver;

    // stores session id in `X-My-Own-Session` header
    $session->setDriver(new HeaderDriver());
    

    use Phossa2\Session\Validator\RemoteIp;

    $session->addValidator(new RemoteIp());
    

    use Phossa2\Session\Generator\UuidGenerator;

    $session->setGenerator(new UuidGenerator());