PHP code example of horizom / session

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

    

horizom / session example snippets


$session->start(array $options = []);

$session->isStarted();

$session->set(string $name, mixed $value = null);

$session->get(string $name, mixed $default = null);

$session->all();

$session->has(string $name);

$session->replace(array $data);

$session->pull(string $name, mixed $default = null);

$session->remove(string $name);

$session->clear();

$session->getId();

$session->setId(string $sessionId);

$session->regenerateId(bool $deleteOldSession = false);

$session->getName();

$session->setName(string $name);

$session->destroy();

use Horizom\Session\Session;

$session = new Session();

use Horizom\Session\Facades\Session;

$session->start();

$session->start([
    // 'cache_expire' => 180,
    // 'cache_limiter' => 'nocache',
    // 'cookie_domain' => '',
    'cookie_httponly' => true,
    'cookie_lifetime' => 8000,
    // 'cookie_path' => '/',
    'cookie_samesite' => 'Strict',
    'cookie_secure'   => true,
    // 'gc_divisor' => 100,
    // 'gc_maxlifetime' => 1440,
    // 'gc_probability' => true,
    // 'lazy_write' => true,
    // 'name' => 'PHPSESSID',
    // 'read_and_close' => false,
    // 'referer_check' => '',
    // 'save_handler' => 'files',
    // 'save_path' => '',
    // 'serialize_handler' => 'php',
    // 'sid_bits_per_character' => 4,
    // 'sid_length' => 32,
    // 'trans_sid_hosts' => $_SERVER['HTTP_HOST'],
    // 'trans_sid_tags' => 'a=href,area=href,frame=src,form=',
    // 'use_cookies' => true,
    // 'use_only_cookies' => true,
    // 'use_strict_mode' => false,
    // 'use_trans_sid' => false,
]);

Session::start();

$session->isStarted();

Session::isStarted();

$session->set('foo', 'bar');

Session::set('foo', 'bar');

$session->get('foo'); // null if attribute does not exist

$session->get('foo', false); // false if attribute does not exist

Session::get('foo');

$session->all();

Session::all();

$session->has('foo');

Session::has('foo');

$session->replace(['foo' => 'bar', 'bar' => 'foo']);

Session::replace(['foo' => 'bar', 'bar' => 'foo']);

$session->pull('foo'); // null if attribute does not exist

$session->pull('foo', false); // false if attribute does not exist

Session::pull('foo');

$session->remove('foo');

Session::remove('foo');

$session->clear();

Session::clear();

$session->getId();

Session::getId();

$session->setId('foo');

Session::setId('foo');

$session->regenerateId();

$session->regenerateId(true);

Session::regenerateId();

$session->getName();

Session::getName();

$session->setName('foo');

Session::setName('foo');

$session->destroy();

Session::destroy();