As of PHP 7.0, you can implement SessionUpdateTimestampHandlerInterface to
define your own session id validating method like validate_sid and the timestamp updating method like update_timestamp in the non-OOP prototype of session_set_save_handler().
SessionUpdateTimestampHandlerInterface is a new interface introduced in PHP 7.0, which has not been documented yet. It has two abstract methods: SessionUpdateTimestampHandlerInterface :: validateId($sessionId) and SessionUpdateTimestampHandlerInterface :: updateTimestamp($sessionId, $sessionData).
<?php
/*
@author Wu Xiancheng
Code structure for PHP 7.0+ only because SessionUpdateTimestampHandlerInterface is introduced in PHP 7.0
With this class you can validate php session id and update the timestamp of php session data
with the OOP prototype of session_set_save_handler() in PHP 7.0+
*/
class PHPSessionXHandler implements SessionHandlerInterface, SessionUpdateTimestampHandlerInterface {
public function close(){
// return value should be true for success or false for failure
// ...
}
public function destroy($sessionId){
// return value should be true for success or false for failure
// ...
}
public function gc($maximumLifetime){
// return value should be true for success or false for failure
// ...
}
public function open($sessionSavePath, $sessionName){
// return value should be true for success or false for failure
// ...
}
public function read($sessionId){
// return value should be the session data or an empty string
// ...
}
public function write($sessionId, $sessionData){
// return value should be true for success or false for failure
// ...
}
public function create_sid(){
// available since PHP 5.5.1
// invoked internally when a new session id is needed
// no parameter is needed and return value should be the new session id created
// ...
}
public function validateId($sessionId){
// implements SessionUpdateTimestampHandlerInterface::validateId()
// available since PHP 7.0
// return value should be true if the session id is valid otherwise false
// if false is returned a new session id will be generated by php internally
// ...
}
public function updateTimestamp($sessionId, $sessionData){
// implements SessionUpdateTimestampHandlerInterface::validateId()
// available since PHP 7.0
// return value should be true for success or false for failure
// ...
}
}
?>