Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php class CustomSessionHandler implements \SessionHandlerInterface { /** * @var array<string, string> */ private $storage = []; public function close(): bool { return true; } public function destroy($id): bool { unset($this->storage[$id]); return true; } public function gc($max_lifetime): int { return 0; } public function open($path, $name): bool { return true; } public function read($id) { if (array_key_exists($id, $this->storage)) { return $this->storage[$id]; } return false; } public function write($id, $data): bool { $this->storage[$id] = $data; return true; } public function getStorage(): array { return $this->storage; } } echo 'Before init: ', ini_get('session.save_handler'). "\n"; $handler = new CustomSessionHandler(); session_name('helloSID'); session_id('session_id'); session_set_save_handler($handler); session_start(['cookie' => '']); ini_set('session.save_handler', 'user'); echo 'After init: ', ini_get('session.save_handler'). "\n"; var_dump($handler->getStorage());
Copy Clear