PHP code example of phpsoftbox / session

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

    

phpsoftbox / session example snippets


use PhpSoftBox\Session\Session;
use PhpSoftBox\Session\Store\NativeSessionStore;

$session = new Session(new NativeSessionStore());
$session->start();

$session->set('user_id', 1);
$session->flash('notice', 'Saved');

$session->save();

use PhpSoftBox\Cookie\CookieQueue;
use PhpSoftBox\Session\Config\SessionConfig;
use PhpSoftBox\Session\Session;
use PhpSoftBox\Session\Store\DatabaseSessionStore;

$store = new DatabaseSessionStore(
    connections: $connections,
    cookies: new CookieQueue(),
    config: new SessionConfig(name: 'psb_session'),
    userIdKeys: [
        'web' => 'auth.user_id',
        'tenant' => 'tenant.auth.user_id',
    ],
);

$session = new Session($store);

use PhpSoftBox\Session\Http\CsrfMiddleware;
use PhpSoftBox\Session\Http\SessionMiddleware;

$sessionMw = new SessionMiddleware($session);
$csrfMw = new CsrfMiddleware($session);
bash
php psb session:prune --max-lifetime 86400
bash
php psb session:prune --dry-run