PHP code example of carry0987 / session-manager
1. Go to this page and download the library: Download carry0987/session-manager 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/ */
carry0987 / session-manager example snippets
use carry0987\SessionManager\SessionManager;
// Create a SessionManager instance, you may optionally supply a custom session name and cookie parameters
$sessionManager = new SessionManager('MY_SESSION_NAME', [
'lifetime' => 3600, // Cookie lifetime
'secure' => true, // Send only over HTTPS
'httponly' => true, // Accessible only through the HTTP protocol
'samesite' => 'Strict' // Strict same-site policy
]);
// Set a session variable
$sessionManager->set('username', 'user123');
// Retrieve a session variable
$username = $sessionManager->get('username');
// Destroy the session
$sessionManager->destroy();
// Renew the session
$sessionManager->renew('MY_SESSION_NAME');