From 630144db19b9199b775902148309c90502d34f78 Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Sat, 6 Jun 2015 15:29:31 +0200 Subject: [PATCH] finish log method --- lib/session_handler.inc.php | 58 +++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lib/session_handler.inc.php diff --git a/lib/session_handler.inc.php b/lib/session_handler.inc.php new file mode 100644 index 0000000..bd3a771 --- /dev/null +++ b/lib/session_handler.inc.php @@ -0,0 +1,58 @@ +savePath = $savePath; + if (!is_dir($this->savePath)) { + mkdir($this->savePath, 0777); + } + + return true; + } + + function close() { + return true; + } + + function read($id) { + return (string)@file_get_contents("$this->savePath/qt_sess_$id"); + } + + function write($id, $data) { + return file_put_contents("$this->savePath/qt_sess_$id", $data) === false ? false : true; + } + + function destroy($id) { + $file = "$this->savePath/qt_sess_$id"; + if (file_exists($file)) { + unlink($file); + } + + return true; + } + + function gc($maxlifetime) { + foreach (glob("$this->savePath/qt_sess_*") as $file) { + if (filemtime($file) + $maxlifetime < time() && file_exists($file)) { + unlink($file); + } + } + + return true; + } +} + +$handler = new FileSessionHandler(); +session_set_save_handler( + array($handler, 'open'), + array($handler, 'close'), + array($handler, 'read'), + array($handler, 'write'), + array($handler, 'destroy'), + array($handler, 'gc') +); + +// the following prevents unexpected effects when using objects as save handlers +register_shutdown_function('session_write_close'); +?> -- 2.39.2