PHP code example of onesimus-systems / ossession

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

    

onesimus-systems / ossession example snippets


use \Onesimus\Session\SessionManager

// First we need to register the session handler
$pdo = new PDO(...);
$options = [
	'timeout' => 6 // hours
	'gclotto' => [1, 100] // Chances a garbage collection will occur
	'table' => 'sessions' // Database table that houses the session data. It must have three fields called 'id', 'data', and 'last_accessed'. 'last_accessed' is an int as times are stored in Unix time.
];

SessionManager::register($pdo, $options);
SessionManager::startSession('php-session-name');

// Manipulate session data
SessionManager::set('userid', 2);
SessionManager::get('themename', 'default'); // get will either return the session value if it exists or whatever is passed as the second argument. By default it will return null if the session data doesn't exist.

SessionManager::clear(); // Clear a session