1. Go to this page and download the library: Download pskuza/php_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/ */
pskuza / php_session example snippets
sh
php composer.phar
php
ession\session;
//for memcached as cache
//check doctrine/cache on how to use the others
$memcached = new Memcached();
$memcached->setOption(Memcached::OPT_COMPRESSION, false);
$memcached->addServer('127.0.0.1', 11211);
$cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
$cacheDriver->setMemcached($memcached);
//for mysql session storage
//check pdo for other connection handlers
$db = \ParagonIE\EasyDB\Factory::create(
'mysql:host=127.0.0.1;dbname=notdev',
'notroot',
'averysecurerandompassword'
);
$session = new php_session\session($db, $cacheDriver);
session_set_save_handler($session, true);
//we have a valid session
$session->start();
//write someting to it
$session->set(['somesessiondata' => 'test']);
//print it
var_dump($_SESSION);
//regenrate session id
//you should do this when the user privilege changes (not logged in => logged in or otherwise)
$session->regenerate_id();
//terminate the session (logout)
$session->logout();
//for more up to date usage see tests/SessionMysqlMemcached.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.