PHP code example of hoa / session

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

    

hoa / session example snippets


$user = new Hoa\Session\Session('user');

if ($user->isEmpty()) {
    echo 'first time', "\n";
    $user['foo'] = time();
} else {
    echo 'other times', "\n";
    var_dump($user['foo']);
}

Hoa\Event\Event::getEvent('hoa://Event/Session/user:expired')
    ->attach(function (Hoa\Event\Bucket $bucket) {
        echo 'expired', "\n";
    });

$user = new Hoa\Session\Session('user');

if ($user->isEmpty()) {
    $user->hasExpired();
    echo 'first time', "\n";
    $user['foo'] = time();
} else {
    echo 'other times', "\n";
    var_dump($user['foo']);
}

$user->rememberMe('+1 day');

$user->forgetMe();

$user = new Hoa\Session\Session('user');
$user['foo'] = 'bar';
$user->delete();