PHP code example of antonkalmykov / session-muscle

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

    

antonkalmykov / session-muscle example snippets


// settings array
$settings = [
    // cookie name which will store the session id
    'cookieName' => 'sess',
    // session entity to record logs
    'sessLogName' => '.sesslog',
    // session repository in this case be folder,
    // generally it can be any
    'repository' => 'storage/sessions',
    // through a gap to run the garbage collector
    'runRate' => 10,
    // short session lifetime in seconds
    'short' => 60,
    // long session lifetime in seconds
    'long' => 120
];

use SessionMuscle\Adapters\FileAdapter;
$adapter = new FileAdapter();

use SessionMuscle\Session;
$session = new Session($adapter, $settings);

$session->all(); // return array of session data

$session->get($key, $default = ''); // return session data or default value

$session->put($key, $value); // return true on success

$session->has($key); // return true if key exists or false if no

$session->pull($key, $default = ''); // return session data or default value.

$session->delete($key, $default = ''); // true on successful removal or false if no

$session->getSessID(); // current session ID with session type

$session->getRepository();

$session->getCookieName();

$session->getSessionTypes(); // return array of session types

$session->getSessionType(); // return current session type

$session->setSessionType($sessionType);

$session->getSessionSettings(); // return current session settings array

$session->save();

$session->regenerate();

$session->clear();