1. Go to this page and download the library: Download neoflow/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/ */
neoflow / session example snippets
use Neoflow\Session\Session;
use Neoflow\Session\SessionInterface;
use Neoflow\Session\Middleware\SessionMiddleware;
use Psr\Container\ContainerInterface;
return [
// ...
SessionInterface::class => function () {
return new Session([ // Default session options
'name' => 'sid',
'autoRefresh' => true,
'cookie' => [
'lifetime' => 3600,
'path' => '/',
'domain' => null,
'secure' => false,
'httponly' => true,
'samesite' => 'Lax'
],
'iniSettings' => []
]);
},
SessionMiddleware::class => function (ContainerInterface $container) {
$session = $container->get(SessionInterface::class);
return new SessionMiddleware($session);
},
// ...
];
use Neoflow\Session\Middleware\SessionMiddleware;
$app->add(SessionMiddleware::class);
// Set session name.
$name = 'sid'; // Session name
$session = $session->setName($name);
// Set session cookie.
$session = $session->setCookie([
// Cookie options
]);
// Start session.
$started = $session->start();
// Get session status.
$status = $session->getStatus();
// Check whether session is started.
$isStarted = $session->isStarted();
// Generate new session id.
$id = $session->generateId();
// Get session cookie.
$cookie = $session->getCookie();
// Get session id.
$id = $session->getId();
// Get session name.
$name = $session->getName();
// Destroy session.
$destroyed = $session->destroy();
// Get session value by key.
$default = null; // Default value, when key doesn't exists
$value = $session->getValue('key', $default);
// Set session value by key.
$overwrite = true; // Set FALSE to prevent overwrite existing value
$session = $session->setValue('key', 'value', $overwrite);
// Check whether session value exists by key.
$valueExists = $session->hasValue('key');
// Delete session value by key.
$session->deleteValue('key');
// Count number of session values.
$numberOfValues = $session->countValues();
// Get session values.
$values = $session->getValues();
// Clear session values.
$session = $session->clearValues();
// Replace session values by key. Existing values with similar keys will be overwritten.
$recursive = true; // Set TRUE to enable recursive replacement
$session = $session->replaceValues([
// Array with key/value pairs
], $recursive);
// Set session values. Existing values will be overwritten.
$session = $session->setValues([
// Array with key/value pairs
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.