====== V6 Session Management ======
~~NOTOC~~
Session management in version 6 differs from version 5 in that it is an integrated part of the core ADOdb object. It can be initialized without additional configuration (assuming that the database table is installed). All of the available options, such as compression or encryption, are pre-configured into the connection.
===== Default Session Initialization =====
/*
* Standard V6 configuration settings
*/
$acd = new ADOdb\ADOConnectionDefinitions($streamHandlers);
$acd->driver = 'mysqli';
$acd->fetchMode = 1;
/*
* Start up a new connection object
*/
$obj = new ADOdb\connector($acd);
/*
* Obtain a database connection
*/
$db = $obj->connect('127.0.0.1',"adodb","adodb",'employees');
/*
* Create an ADOdb session connection
*/
$session = $obj->startSession();
$session->lifetime(3000);
/*
* Start thr PHP Session handler
*/
session_start();
/*
* Manipulate session data
*/
$_SESSION['name'] = 'MARK';
$_SESSION['data'] = array('bird'=>'chicken','reptile'=>'paper');
===== Session Definitions Class =====
All of the connection definitions are kept by default in the **\ADOdb\sessions\ADOSessionDefinitions** class. The class id defined as follows
class ADOSessionDefinitions
{
/*
* Defines the debugging level
*/
public int $debug = 0;
/*
* Is the session connection readonly
*/
public bool $readOnly = false;
/*
* Defines the sessions table name
*/
public string $tableName = 'sessions2';
/*
* Must have a large object if we are using compression
*/
public ?string $largeObject = '';
/*
* What fields will be retrieved from the database on
* read
*/
public string $readFields = 'sessdata';
/*
* Defines the crypto method. Default none
*/
const CRYPTO_NONE = 0;
const CRYPTO_MD5 = 1;
const CRYPTO_MCRYPT = 2;
const CRYPTO_SHA1 = 3;
const CRYPTO_SECRET = 4;
public int $cryptoMethod = 0;
/*
* Defines the compression method - DEfault none
* You must use a blob field to support compressed
* data
*/
const COMPRESS_NONE = 0;
const COMPRSS_BZIP = 1;
const COMPRESS_GZIP = 2;
public int $compressionMethod = 0;
/*
* Serializtion methods
*/
const SER_DEFINED = 0;
const SER_PHP = 1;
const SER_PHP_BINARY = 2;
const SER_PHP_SERIALIZABLE = 3;
const SER_PHP_WDDX = 4;
public ?int $serializationMethod = 3;
public bool $optimizeTable = true;
/**
* The target class for session management. Extend
* as necessary
*/
public ?string $sessionManagementClass = null;
}
===== Session Definitions =====
The following definitions / configurations are available:
==== Debug ====
Activitating debug mode for session mode is independent of the main driver. Critical debug messages are still sent to the critical monolog channel.
==== ReadOnly ====
==== Table Name ====
The table name installed to manage the database backed session
==== Large Object ====
If you use a large object to manage the session data, you should specify the data type here, either **clob** or **blob**. This allows session management to use the correct large-object handling functions. If you use any extension that writes binary data into the database you must use a format that supports it.
==== Read Fields ====
The fields that are being read from the database.
==== cryptoMethod ====
The encryption method that you want to apply to the session data. Only MD5 and SHA1 methods are currently available
==== Compression Method ====
Either BZIP or GZIP compression is available. To use compression, you must use a column format for **sessdata** that accepts binary data storage
==== serializationMethod ====
The PHP serialization method used to encode the data. The default serialization method has changed since version 5. ADOdb now uses the standard serialization, so that the function **adodb_unserialize()** is no longer required, unless you are working with legacy code.
==== optimizeTable ====
Use the table optimization feature of the database management system (if available). This is a function of what database is used.
==== sessionManagementClass ====
If you want to replace the entire class, you can place the entire class path in this location. The class must contain all of the necessary methods associated with session handling.
$this->sessionManagementClass = '\My\Custom\ADOSession';
==== Example with Compression and Encryption ====
/*
* Establish a connection....
*/
$db = $obj->connect();
/*
* Define some session definitions
*/
%sessionDefinitions = new \ADOdb\sessions\ADOSessionDefinitions;
$sessionDefinitions->cryptoMethod = $sessionDefinitions::CRYPTO_MD5;
$sessionDefinitions->compressionMethod = $sessionDefinitions::COMPRESS_GZIP;
$sessionDefinitions->largeObject = 'clob';
/*
* Create an ADOdb session connection
*/
$session = $obj->startSession($sessionDefinitions);
$session->lifetime(3000);
session_start();