1. Go to this page and download the library: Download lithemod/session-support 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/ */
lithemod / session-support example snippets
session_start();
use Lithe\Support\Session;
Session::put('username', 'john_doe');
Session::destroy(); // Clears all session variables and destroys the session
if (Session::has('username')) {
echo 'Username is set.';
} else {
echo 'Username is not set.';
}
// Check multiple variables
if (Session::has(['username', 'email'])) {
echo 'Both variables are set.';
}
Session::regenerate(); // Regenerates the session ID, invalidating the old session
$currentSessionId = Session::getId();
echo $currentSessionId; // Displays the current session ID
Session::setId('custom_session_id');
$allSessions = Session::all();
print_r($allSessions); // Displays all session variables
// Set a session variable
$session = new Session();
$session->username = 'john_doe'; // Calls Session::put('username', 'john_doe')
// Get a session variable
echo $session->username; // Calls Session::get('username')
try {
Session::put('key', 'value'); // Will throw exception if session is not active
} catch (RuntimeException $e) {
echo $e->getMessage(); // Output: The session is not active.
}
use Lithe\Support\Session\Flash;
// Using the set method
Flash::set('success', 'The operation was completed successfully.');
// Using the magic property
$flash = new Flash();
$flash->info = 'Welcome to our website!';
$message = Flash::get('success');
echo $message; // Output: The operation was completed successfully.
// Using the magic property
$infoMessage = $flash->info;
echo $infoMessage; // Output: Welcome to our website!