Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

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
(
)
HomeMenu