summaryrefslogtreecommitdiffstats
path: root/inc/session.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2013-10-15 19:24:01 +0200
committerSimon Rettberg2013-10-15 19:24:01 +0200
commit43e406068af8f2ae3d77301926bb5d31f392c961 (patch)
treea71f2fda66e789a6a1d2a9437bc1e37027e4ee93 /inc/session.inc.php
downloadslx-admin-43e406068af8f2ae3d77301926bb5d31f392c961.tar.gz
slx-admin-43e406068af8f2ae3d77301926bb5d31f392c961.tar.xz
slx-admin-43e406068af8f2ae3d77301926bb5d31f392c961.zip
Initial commit
Diffstat (limited to 'inc/session.inc.php')
-rw-r--r--inc/session.inc.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/inc/session.inc.php b/inc/session.inc.php
new file mode 100644
index 00000000..a62c5cd3
--- /dev/null
+++ b/inc/session.inc.php
@@ -0,0 +1,49 @@
+<?php
+
+require_once('config.php');
+
+@mkdir(CONFIG_SESSION_DIR, 0700);
+@chmod(CONFIG_SESSION_DIR, 0700);
+
+session_set_save_handler('sh_open', 'sh_close', 'sh_read', 'sh_write', 'sh_destroy', 'sh_gc');
+
+// Pretty much a reimplementation of the default session handler: Plain files
+// Needs to be switched to db later
+
+function sh_open($path, $name)
+{
+ return true;
+}
+
+function sh_close()
+{
+ return true;
+}
+
+function sh_read($id)
+{
+ return (string)@file_get_contents(CONFIG_SESSION_DIR . '/slx-session-' . $id);
+}
+
+function sh_write($id, $data)
+{
+ return @file_put_contents(CONFIG_SESSION_DIR . '/slx-session-' . $id, $data);
+}
+
+function sh_destroy($id)
+{
+ return @unlink(CONFIG_SESSION_DIR . '/slx-session-' . $id);
+}
+
+function sh_gc($maxAgeSeconds)
+{
+ $files = @glob(CONFIG_SESSION_DIR . '/slx-session-*');
+ if (!is_array($files)) return false;
+ foreach ($files as $file) {
+ if (filemtime($file) + $maxAgeSeconds < time()) {
+ @unlink($file);
+ }
+ }
+ return true;
+}
+