- session_set_save_handler: documentation ( source)
- session_start: documentation ( source)
- session_id: documentation ( source)
<?php
class DemoBugSessionHandler implements SessionHandlerInterface
{
public function open($save_path, $name)
{
return true;
}
/**
* Read session data
* @link https://php.net/manual/en/sessionhandlerinterface.read.php
* @param string $session_id The session id to read data for.
* @return string <p>
* Returns an encoded string of the read data.
* If nothing was read, it must return an empty string.
* Note this value is returned internally to PHP for processing.
* </p>
* @since 5.4.0
*/
public function read($session_id)
{
// Simulate a session ID regeneration.
\session_id('newsessionid');
return '';
}
/**
* Write session data
* @link https://php.net/manual/en/sessionhandlerinterface.write.php
* @param string $session_id The session id.
* @param string $session_data <p>
* The encoded session data. This data is the
* result of the PHP internally encoding
* the $_SESSION superglobal to a serialized
* string and passing it as this parameter.
* Please note sessions use an alternative serialization method.
* </p>
* @return bool <p>
* The return value (usually TRUE on success, FALSE on failure).
* Note this value is returned internally to PHP for processing.
* </p>
* @since 5.4.0
*/
public function write($session_id, $session_data)
{
// Print back to the user agent the $session_id
// that is going to be persisted when the script finishes.
echo $session_id . PHP_EOL;
return true;
}
public function destroy($session_id)
{
return true;
}
public function close()
{
return true;
}
public function gc($maxlifetime)
{
return true;
}
}
session_set_save_handler(new \DemoBugSessionHandler(), true);
session_start();