session_register_shutdown
Description
The session_register_shutdown of Session for PHP registers the session shutdown function.
Syntax
session_register_shutdown(): void
Return
No value is returned.
Examples
1 · void
<? class MySessionHandler implements SessionHandlerInterface { private $savePath; public function open($savePath, $sessionName) { $this->savePath = $savePath; if(!is_dir($this->savePath)) { mkdir($this->savePath, 0777); } return true; } public function close() { return true; } public function read($sessionId) { return (string)@file_get_contents("$this->savePath/sess_$sessionId"); } public function write($sessionId, $data) { return file_put_contents("$this->savePath/sess_$sessionId", $data) === false ? false : true; } public function destroy($sessionId) { $file = "$this->savePath/sess_$sessionId"; if(file_exists($file)) { unlink($file); } return true; } public function gc($lifetime) { foreach(glob("$this->savePath/sess_*") as $file) { if(filemtime($file) + $lifetime < time() && file_exists($file)) { unlink($file); } } return true; } } $sessionhandler = new MySessionHandler(); $register_shutdown = false; session_set_save_handler($sessionhandler, $register_shutdown); session_register_shutdown(); session_start(); print_r($_SESSION);
Array ( )
Links
Session
- session_abort
- session_cache_expire
- session_cache_limiter
- session_commit
- session_create_id
- session_decode
- session_destroy
- session_encode
- session_gc
- session_get_cookie_params
- session_id
- session_module_name
- session_name
- session_regenerate_id
- session_reset
- session_save_path
- session_set_cookie_params
- session_set_save_handler
- session_start
- session_status
- session_unset
- session_write_close