PHP code example of skt-t1-byungi / session

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

    

skt-t1-byungi / session example snippets


use SktT1Byungi\Session\Session;

 Session::manager()->start();
 Session::set('aaa', '111');
 
 var_dump(Session::get('aaa') === $_SESSION['aaa']);
 // true

 Session::manager()->id("id")->name("name")->start();
 // session_id("id");
 // session_id("name");
 // session_start();
 
 Session::manager()->close()->destroy();
 // session_write_close();
 // session_destroy();
 
 Session::manager()->settings([
    'cookie_httponly' => true,
    'use_only_cookies' => true,
 ]);
 // ini_set("session.cookie_httponly", true);
 // ini_set("session.use_only_cookies", true);
 
 Session::manager()->handler(new CustomHandler)->start();
 // used custom handler

Session::set('aaa', [
    'bbb' => [
        'ccc' => 111,
        'ddd' => 222,
    ],
]);
Session::set('eee', '333');
Session::set('fff', '444');

echo Session::get('aaa.bbb.ccc');
// 111

var_dump(Session::has('ccc'), Session::has('eee'));
// false, true

var_dump(Session::only(['eee', 'fff']));
// ['eee' => '333', 'fff' => '444']

var_dump(Session::except(['aaa']));
// ['eee' => '333', 'fff' => '444']

Session::forget('aaa.bbb'); //or Session::remove('aaa.bbb');
// unset($_SESSION['aaa']['bbb']);

Session::set('aaa', [
    [
        "name" => "bangi",
        "position" => "god",
    ],
    [
        "name" => "faker",
        "position" => "human",
    ],
    [
        "name" => "duke",
        "position" => "human",
    ],
    [
        "name" => "wolf",
        "position" => "pig",
    ],
]);

var_dump(Session::collect('aaa')->where('position', 'human')->all());
// [
//     1 => [
//         "name" => "faker",
//         "position" => "human",
//     ],
//     2 => [
//         "name" => "duke",
//         "position" => "human",
//     ],
// ]

$app->add(Session::manager()->handler(new CustomHandler)->id('mySess')->middleware());