PHP code example of horde / sessionhandler

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

    

horde / sessionhandler example snippets


use Horde\SessionHandler\SessionHandler;
use Horde\SessionHandler\Storage\FileBackend;

$handler = new SessionHandler(
    backend: new FileBackend('/var/sessions'),
);

// Create, read, write, done.
$session = $handler->create();
$session->set('user', 'alice');
$handler->save($session);

// Later...
$session = $handler->load($session->getId());
echo $session->get('user'); // alice

session_set_save_handler($handler, true);
session_start();
$_SESSION['user'] = 'alice';

new FileBackend(string $path)
new SqlBackend(Horde\Db\Adapter $db, string $table = 'horde_sessionhandler')
new HashtableBackend(Horde_HashTable_Base & Horde_HashTable_Lock $ht, bool $track = false)
new StackBackend(SessionStorageBackend ...$backends)   // last is master
new ExternalBackend(Closure $read, Closure $write, Closure $delete)
new BuiltinBackend(string $path = '')

$session->set('cart', []);       // marks dirty
$session->get('cart');           // []
$session->has('cart');           // true
$session->remove('cart');        // marks dirty
$session->keys();                // ['remaining', 'keys']
$session->isDirty();             // true