1. Go to this page and download the library: Download flightphp/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/ */
flightphp / session example snippets
// Create a session instance with default settings
$session = new flight\Session();
// Store some data
$session->set('user_id', 123);
$session->set('username', 'johndoe');
$session->set('is_admin', false);
// Retrieve data
echo $session->get('username'); // Outputs: johndoe
// Use a default value if the key doesn't exist
echo $session->get('preferences', 'default_theme'); // Outputs: default_theme
// Remove a session value
$session->delete('is_admin');
// Check if a value exists
if ($session->get('user_id')) {
echo 'User is logged in!';
}
// Clear all session data
$session->clear();
$session = new flight\Session([
'save_path' => '/custom/path/to/sessions', // Custom directory for storing session files
'encryption_key' => 'your-secret-32-byte-key', // Enable encryption with a secure key
'auto_commit' => true, // Automatically commit session changes on shutdown
'start_session' => true, // Start the session automatically
'test_mode' => false, // Enable for testing without affecting PHP's session state
]);
// Create a session with encryption enabled
$session = new flight\Session([
'encryption_key' => 'a-secure-32-byte-key-for-aes-256-cbc',
]);
// Now all session data will be automatically encrypted when stored
$session->set('credit_card', '4111-1111-1111-1111');
// Regenerate the session ID and keep the current session data
$session->regenerate();
// Regenerate the session ID and delete the old session data
$session->regenerate(true);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.