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.

Example

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();
?>
Introduction to HTTP_Session (Previous) HTTP_Session2 (Next)
Last updated: Tue, 16 Sep 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.