I am looking for a way to read the contents of a PHP session without actually replacing the running session of the current request.
Lets say I have a running session (started before with session_start(), using the default session handler and the session_id given by the PHPSESSID cookie) Now I have another (valid) session_id and I want to read some of the data stored in that session.
The only way I can think of is to replace the current session with $oldSession = session_id(), set the new session with session_id($newId), then read the data from $_SESSION and then restart the original session with session_id($oldSession) - probably involving some aditional calls of session_commit() and session_start().
But I prefer to not touch the current, running session at all...
PHP 5.4 introduces the SessionHandler class (http://php.net/manual/de/class.sessionhandler.php) but manually calling $SessionHandler->read doesn't seem to work either
$handler = new SessionHandler();
var_dump($handler->read($session));
//Fatal error: SessionHandler::read(): Cannot call default session handler
I am using the native php memcached session handler
Thank you for any tipps!
SessionHandlerisn't intended for applications to call directly. They're supposed to implement a subclass if they want custom session handling, and then PHP will call their session handler. - Barmar