PHP code example of aeforge / session

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

    

aeforge / session example snippets


use Aeforge\Session\Session;

// Start a new session instance
$session = new Session();
// Add expiring time to 60 (in minutes)
$session->register(60);
//Set a normal session key and value
$session->set("session_key", "session_value");
//Set a flashed session key and value (useful for forms errors for example)
$session->flash("flashed_key", "flashed_value");
// Get a normal session value using a key
echo $session->get("hello");
//Get a flashed session value using a key
echo $session->getFlashed("hello");
// Clears both the flash session array and the data session array(normal session)
$session->clear();
// Clear the data array only(normal session)
$session->clearData();
// Clear the flashed array only
$session->clearFlashed();
// Ends the session
$session->destroy();
// Regenerates the session id
$session->regenerate();
// Check if the session expired
$session->isExpired ();