Session Support 

  Installation

ADOdb Lite supports a new session handler that offers support for ADOdb's encryption and compression options. ADOdb Lite's session handler is 1/3 the size of ADOdb's and over 350% faster.

This package does not support cob sessions and it is unlikely to support them in the future.

You will need to create a table for your session support. The session table is different from the table used in ADOdb. This is the only real departure from the ADOdb Session system.

Here is the MySql code to create the database you need.

CREATE TABLE /*! IF NOT EXISTS */ sessions (
    ID INT NOT NULL AUTO_INCREMENT,
    SessionID VARCHAR(64),
    session_data TEXT DEFAULT '',
    expiry INT(11),
    expireref VARCHAR(64) DEFAULT '',
    PRIMARY KEY (ID),
    INDEX SessionID (SessionID)
    INDEX expiry (expiry)
);

The following variables from ADOdb are supported.

$ADODB_SESSION_DRIVER='database'; # mysql, mssql, ect.
$ADODB_SESSION_CONNECT='localhost'; # database server address
$ADODB_SESSION_USER ='user';
$ADODB_SESSION_PWD ='password';
$ADODB_SESSION_DB ='database';
$ADODB_SESSION_TBL = 'sessions'; # setting this is optional and will normally use the database name of sessions

The following commands are supported.

ADODB_Session::filter($object);
    $object = This is the class object for the filter the session handler will use.

ADODB_Session::encryptionKey($key);
    $key = Specify a unique encryption key for the encryption methods. The
                  default key is 'ADOdb Lite'.

Expiration Notify is supported so when a database session expires for a user the specified function will be executed.

Example:

<?
require_once 'adodb.inc.php';
require_once 'session/adodb-session.php';

function ExpiredSession($expireref, $sesskey)
{
    echo "Session Expired: $expireref<br>";
    echo "Session Key: $sesskey<br><br>";
}

$USERID = 44;

$ADODB_SESSION_DRIVER='mysql';
$ADODB_SESSION_CONNECT='localhost';
$ADODB_SESSION_USER ='pj';
$ADODB_SESSION_PWD ='pj';
$ADODB_SESSION_DB ='pj';
$ADODB_SESSION_EXPIRE_NOTIFY = array('USERID','ExpiredSession');
session_start();
?>

When the database session expires for USERID 44 the ExpiredSession function is called. This is called when the PHP session handler performs a scheduled garbage collection or when your program destroys the users session.

 

  Encrypted Sessions

You can start ADOdb Lite Encrypted Sessions using the following code.

<?
require_once 'adodb.inc.php';
require_once 'session/adodb-cryptsession.php';
?>

You will notice the only change is to use adodb-cryptsession.php instead of adodb-session.php.

I DO NOT recommend using this method unless you want to use the MD5 encryption.

I recommend using this method to initialize encrypted sessions.

<?
require_once 'adodb.inc.php';
require_once 'session/adodb-session.php';
require_once 'session/adodb-encrypt-md5.php'
;
ADODB_Session::filter(new ADODB_Encrypt_MD5());
?>

With this method you can more easily change the encryption and add compression.

 

  Supported Encrytion Methods

You can start ADOdb Lite Encrypted Sessions using the following code.

<?
require_once 'session/adodb-encrypt-md5.php';   // MD5 Encryption
ADODB_Session::filter(new ADODB_Encrypt_MD5());
?>

<?
require_once 'session/adodb-encrypt-mycrypt.php';   // Mycrypt Encryption
ADODB_Session::filter(new ADODB_Encrypt_MCrypt());
?>

<?
require_once 'session/adodb-encrypt-ordcrypt.php';   // OrdCrypt Encryption
ADODB_Session::filter(new ADODB_Encrypt_OrdCrypt());
?>

<?
require_once 'session/adodb-encrypt-secret.php';   // Secret Encryption
ADODB_Session::filter(new ADODB_Encrypt_Secret());
?>

<?
require_once 'session/adodb-encrypt-sha1.php';   // SHA1 Encryption
ADODB_Session::filter(new ADODB_Encrypt_SHA1());
?>


  Compressed Sessions

To add compression use the same method as adding encryption.

Example:

<?
require_once 'adodb.inc.php';
require_once 'session/adodb-session.php';
require_once 'session/adodb-compress-gzip.php';
ADODB_Session::filter(new ADODB_Compress_Gzip());
?>

You may even compress the encrypted session data by stacking filters.

<?
require_once 'adodb.inc.php';
require_once 'session/adodb-session.php';
require_once 'session/adodb-encrypt-md5.php'
;
ADODB_Session::filter(new ADODB_Encrypt_MD5());
require_once 'session/adodb-compress-gzip.php'
;
ADODB_Session::filter(new ADODB_Compress_Gzip());
?>

 


  Supported Compression Methods

You can start ADOdb Lite Compressed Sessions using the following code.

<?
require_once 'session/adodb-compress-bzip2.php';   // Bzip2 Compression
ADODB_Session::filter(new ADODB_Compress_Bzip2());
?>

<?
require_once 'session/adodb-compress-gzip.php';   // Gzip Compression
ADODB_Session::filter(new ADODB_Compress_Gzip());
?>

 

Copyright ©2005, 2006 Mark Dickenson