1. Go to this page and download the library: Download bryanjhv/slim-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/ */
$container = new \DI\Container();
// Register globally to app
$container->set('session', function () {
return new \SlimSession\Helper();
});
\Slim\Factory\AppFactory::setContainer($container);
$app->get('/', function ($req, $res) {
// or $this->get('session') if registered
$session = new \SlimSession\Helper();
// Check if variable exists
$exists = $session->exists('my_key');
$exists = isset($session->my_key);
$exists = isset($session['my_key']);
// Get variable value
$my_value = $session->get('my_key', 'default');
$my_value = $session->my_key;
$my_value = $session['my_key'];
// Set variable value
$app->get('session')->set('my_key', 'my_value');
$session->my_key = 'my_value';
$session['my_key'] = 'my_value';
// Merge value recursively
$app->get('session')->merge('my_key', ['first' => 'value']);
$session->merge('my_key', ['second' => ['a' => 'A']]);
$letter_a = $session['my_key']['second']['a']; // "A"
// Delete variable
$session->delete('my_key');
unset($session->my_key);
unset($session['my_key']);
// Destroy session
$session::destroy();
// Get session id
$id = $this->session::id();
return $res;
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.