PHP code example of xp-forge / sessions

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

    

xp-forge / sessions example snippets


use web\session\{InFileSystem, ForTesting};

// Instantiate session factory
$sessions= new InFileSystem('/tmp');
$sessions= (new ForTesting())->lasting(3600)->named('psessionid');

// Create a new session
$session= $sessions->create();

// Open an existing session...
if ($session= $sessions->open($sessionId)) { … }

// ...or locate session attached to a request
if ($session= $sessions->locate($request)) { … }

// Basic I/O operations
$session->register('key', 'value');
$value= $session->value('key');
$keys= $session->keys();
$session->remove('key');

// Destroy
$session->destroy();

// Close session...
$session->close();

// ...or close and then transmit session to response.
$session->transmit($response);

// This will omit the "Secure" flag from session cookies in dev environment
$sessions= new InFileSystem('/tmp');
if ('dev' === $this->environment->profile()) {
  $sessions->cookies()->insecure(true);
}