Database container
Database container –
Store session data in a database with HTTP_Session
Overview
HTTP_Session lets you store the session data in a database making use of the DB, MDB and MDB2 packages.
Пример
Using MDB2 to store session data in a database
<?php
/* create the following table in your database
CREATE TABLE sessiondata (
id varchar(32) NOT NULL,
expiry int(10),
data text,
PRIMARY KEY (id)
);
*/
require_once 'HTTP/Session.php';
HTTP_Session::useTransSID(false);
HTTP_Session::useCookies(false);
// enter your DSN
HTTP_Session::setContainer('MDB2', array('dsn' => 'mysql://root:password@localhost/database',
'table' => 'sessiondata'));
/*
// using an existing MDB2 connection
HTTP_Session::setContainer('MDB2', array('dsn' => &$db,
'table' => 'sessiondata'));
*/
HTTP_Session::start('s');
HTTP_Session::setExpire(time() + 60); // set expire to 60 seconds
HTTP_Session::setIdle(time() + 5); // set idle to 5 seconds
if (HTTP_Session::isExpired()) {
//HTTP_Session::replicate('sessiondata_backup'); // Replicate data of current session to specified table
HTTP_Session::destroy();
}
if (HTTP_Session::isIdle()) {
//HTTP_Session::replicate('sessiondata_backup'); // Replicate data of current session to specified table
HTTP_Session::destroy();
}
HTTP_Session::updateIdle();
?>