You could simply create a function wrapper around session_start() that you use.
function my_session_start() {
session_start();
$session_id = session_id();
// write $session_id to database by whatever method you choose
}
// usage
my_session_start();
Or if you want to extend on sessionHandler you could do something like this:
class mySessionHandler extends sessionHandler {
// perhaps a property to store db connection or DB object as needed for writing session id to database
protected $db = null;
public function __construct($db = null) {
if(is_null($db)) {
throw new Exception('Give me a database');
}
// maybe some other validation (could also use type hinting in parameter
$this->db = $db;
}
public function open($save_path, $session_id) {
parent::open($save_path, $session_id);
// not shown - use $this->db to insert $session_id to database
}
}
// usage
$session_handler = new mySessionHandler($db);
session_set_save_handler($session_handler, true);
session_start();
Here you are only overriding the open() method to add the session id to the database.
SessionHandlerthat will accomplish what you want without having to modify the PHP source and compile your own binaries.session_start()of your own as Mike Brant suggests. It depends on where you want to put the code. "auto prepend" could also be of use.