PHP code example of phico / session

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

    

phico / session example snippets


$config = [

    // set the cookie parameters
    'cookie' => [

        'name' => 'ssn',

        'options' => [
            'expires' => 0,
            'path' => '/',
            'domain' => '',
            'secure' => false,
            'httponly' => true,
            'samesite' => 'Lax',
            'prefix' => '',
            'encode' => false,
        ],

    ],

    // set the Time To Live in seconds, sessions will expire after this time
    'ttl' => 3600
];

public function use(): array
{
    return [
        \Phico\Session\SessionMiddleware::class
    ]
}


$session->set('key', 'value');

// or shorthand
$session->key = $value;

$value = $session->get('key');

// optionally specify a default value if key is not in the session
$value = $session->get('key', 'default');

// or shorthand without specifying a default
$value = $session->key;


$exists = $session->has('key');

$session->flash('flash_key', 'flash_value');

$flashValue = $session->get('flash_key');

$session->delete();

$id = $session->id;

$session->regenerate();