PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
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' => '']); echo 'After init: ', ini_get('session.save_handler'). "\n"; var_dump($handler->getStorage());
Show:  
Copy Clear