27/01
2015
Wallogit.com
2017 © Pedro Peláez
SQLSessionHandler is a PHP MySQL Session Handler written for use with PHP-MySQL-PDO-Database-Class, (*1)
composer install jayc89/php-sql-session-handler
CREATE TABLE `session_handler` (
`id` varchar(255) NOT NULL,
`data` mediumtext NOT NULL,
`timestamp` int(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
require 'vendor/autoload.php';
$session = new SQLSessionHandler();
// add db data
$session->setDbDetails('localhost', 'username', 'password', 'database');
// OR alternatively send a MySQLi resource
// $db = new Db(); // https://github.com/jayc89/php-mysql-pdo-database-class
// $session->setDbConnection($db);
$session->setDbTable('session_handler');
session_set_save_handler(array($session, 'open'),
array($session, 'close'),
array($session, 'read'),
array($session, 'write'),
array($session, 'destroy'),
array($session, 'gc'));
register_shutdown_function('session_write_close');
session_start();
MIT, (*2)
Free Software, Hell Yeah!, (*3)
sprainr - https://github.com/sprain/PHP-MySQL-Session-Handler, (*4)