PHP code example of mipotech / yii2-persistent-session

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

    

mipotech / yii2-persistent-session example snippets


'components' => [
    ...
    'persistentSession' => [
        /* Required settings */
        'class' => 'mipotech\persistentsession\PersistentSession',
        
        /* Optional settings */
        //'db' => '...',            // MongoDB application component. Defaults to 'mongodb'
        //'collection' => '...',    // The name of the collection to store the session data. Defaults to 'persistent_session'
        //'cookieClass' => '...'    // The class to used to generate a new cookie. Defaults to 'yii\web\Cookie'
        //'cookieKey' => '...',     // The cookie key to use for identifying the persistent session. Defaults to 'session-id'
        //'cookieParams' => '...',  // The default cookie parameters. Defaults to ['httpOnly' => true, 'secure' => true]
        //'uniqidPrefix' => '...',  // The prefix to use for generating a new session identifier. Defaults to ''
    ]
    ...
]

$persistentSession = Yii::$app->persistentSession;

// check if a session is already open
if ($persistentSession->isActive) ...

// open a session
$persistentSession->open();

// destroys all data registered to a session.
$persistentSession->destroy();

$persistentSession = Yii::$app->persistentSession;

// get a session variable.
$language = $persistentSession->get('language');

// set a session variable. The following usages are equivalent:
$persistentSession->set('language', 'en-US');

// remove a session variable. The following usages are equivalent:
$persistentSession->remove('language');

// check if a session variable exists. The following usages are equivalent:
if ($persistentSession->has('language')) ...