Requires PHP 5.2 or later
“Session Dba” is an example of storing browser session data using Database (dbm-style) Abstraction Layer functions. This class is based on the PHP’s built-in session handler and is a showcase of what can be done. It is NOT recommended for production use.
Before you use “session Dba” be sure you have installed:
If these requirements are met, you are ready to go.
Start a session by creating a session instance specifying the database location and database handler, e.g. $session = new we_sessionDba('/var/php/sessions.db4', 'db4'). You do not have to call session_start(). To see which handlers your server support use function dba_handlers() or look on the phpinfo() page. Also see the list of available DBA handlers. The web server must be able to write the database file/directory. If the file does not exist, it will be created automatically.
The default session name is DBASESSID. Optionally you can define your own, e.g. $session = new we_sessionDba('/var/php/sessions.db4', 'db4', 'CUSTOMSESSIONID').
After you created a session instance you can use built-in PHP session functionality. Data can be stored and retrieved using the $_SESSION variable. You cannot call functions that write session data, like session_write_close(), session_destroy() and session_regenerate_id(). Session data is written automatically by this class.
To destroy a session, call $session->destroy(). This not only destroys the session like session_destroy() does, but also empties the $_SESSION variable and deletes the session cookie.
To regenerate a session, call $session->regenerate_id().
Behaviour of sessions can be changed by editing the session runtime configuration.
require_once 'sessionDba.php';
// Start session using Oracle Embedded Database (formerly Sleepycat Software’s DB4)
try {
$session = new we_sessionDba('/var/php/sessions.db4', 'db4');
} catch( Exception $e ) {
die( $e->getMessage() );
}
// Access session data as usual
$_SESSION['mydata'] = 'my session data';
// Add data to the session
echo $_SESSION['mydata'];
// Get session data
// Regenerate session ID
$session->regenerate_id();
// Destroy session, automatically deleting session cookie and all session data
$session->destroy();