This is what I found and use. I've removed my code so you can just put yours into the event functions:
PHP Code:
<?php
class FileSessionHandler
{
protected $savePath;
protected $sessionName;
function open($savePath, $sessionName)
{
$this->savePath = $savePath;
$this->sessionName = $sessionName;
}
function close()
{
//
}
function read($id)
{
}
function write($id, $data)
{
}
function destroy($id)
{
}
function gc($maxlifetime)
{
//
}
}
$handler = new FileSessionHandler();
session_set_save_handler
(
array($handler, 'open'),
array($handler, 'close'),
array($handler, 'read'),
array($handler, 'write'),
array($handler, 'destroy'),
array($handler, 'gc')
);
// the following prevents unexpected effects when using objects as save handlers
register_shutdown_function('session_write_close');
?>
Save it as a file and simply include it into your script BEFORE calling session_start() but after opening your database connection. You'll also need yourself a table for your sessions (named sessions would be sensible) and at least two columns - one for serialized data and one for the session id. Just including the file will do everything you need automatically so the moment you call session_start(), it will read out from the database (once you've written that code in) and make everything available in the $_SESSION array as normal.
The gc function is for garbage collection. You probably don't want that but if you did and you had a date column you could delete session records that were over a year old etc.