PHP code example of componenta / session

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

    

componenta / session example snippets


use Componenta\Session\SessionData;

$data = new SessionData(['user_id' => 42]);

$data->getInt('user_id');     // 42
$data->set('theme', 'dark');
$data->pull('theme');         // "dark" and removes it
$data->only('user_id');
$data->except('csrf_token');

$data->flash('success', 'Saved');
$data->peekFlashes('success'); // keeps messages
$data->getFlashes('success');  // reads and removes messages

use Componenta\Session\SessionId;

$id = new SessionId('abc123');
(string) $id; // abc123

use Componenta\Session\SessionManager;

$manager = new SessionManager($storage);

$session = $manager->start($id);
$session->data->set('user_id', 42);

$manager->save($session);
$manager->regenerate($session, deleteOld: true);
$manager->destroy($session);