]>
git.datanom.net - qtadmin.git/blob - lib/session_handler.inc.php
2 /* vim: set ts=4 tw=0 sw=4 noet: */
3 require_once $CFG->root
.'config.php';
5 class FileSessionHandler
{
10 public function __construct() {
13 if (isset($CFG->log_level
)) {
14 $this->log_level
= $CFG->log_level
;
19 if (isset($CFG->log_method
)) {
20 $this->log_method
= $CFG->log_method
;
22 $this->log_level
= 'syslog';
25 $this->log("Init FileSessionHandler", 4);
29 private function log($message, $level = 1) {
32 if ($level > $this->log_level
)
39 case 1: $priority = LOG_ERR
; break;
40 case 2: $priority = LOG_WARNING
; break;
41 case 3: $priority = LOG_INFO
; break;
42 case 4: $priority = LOG_DEBUG
; break;
45 switch ($this->log_method
) {
47 if (isset($CFG->log_file
)) {
48 if ($CFG->log_file
[0] == '/') {
49 $file = $CFG->log_file
;
51 $file = $CFG->root
.$CFG->log_file
;
54 $file = $CFG->root
.'qtadmin.log';
56 file_put_contents($file, "[$time]: $message\n", FILE_APPEND | LOCK_EX
);
60 file_put_contents('php://stderr', "[$time]: $message\n");
63 syslog($priority, $message);
68 public function open($savePath, $sessionName) {
69 $this->log("FileSessionHandler->open", 4);
70 $this->savePath
= $savePath;
71 if (!is_dir($this->savePath
)) {
72 mkdir($this->savePath
, 0777);
79 $this->log("FileSessionHandler->close", 4);
84 return (string)@file_get_contents
("$this->savePath/qt_sess_$id");
87 function write($id, $data) {
88 $this->log("FileSessionHandler->write : $id->$data", 4);
89 $result = file_put_contents("$this->savePath/qt_sess_$id", $data);
90 chmod("$this->savePath/qt_sess_$id", 0600);
92 return ($result === false) ?
false : true;
95 function destroy($id) {
96 $this->log("FileSessionHandler->destroy : $id", 4);
97 $file = "$this->savePath/qt_sess_$id";
98 if (file_exists($file)) {
105 function gc($maxlifetime) {
106 $this->log("FileSessionHandler->gc : $maxlifetime", 4);
107 foreach (glob("$this->savePath/qt_sess_*") as $file) {
108 if (filemtime($file) +
$maxlifetime < time() && file_exists($file)) {
117 $handler = new FileSessionHandler();
118 session_set_save_handler(
119 array($handler, 'open'),
120 array($handler, 'close'),
121 array($handler, 'read'),
122 array($handler, 'write'),
123 array($handler, 'destroy'),
124 array($handler, 'gc')
127 // the following prevents unexpected effects when using objects as save handlers
128 register_shutdown_function('session_write_close');
This page took 0.099514 seconds and 6 git commands to generate.