aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Web/SessionHandler.php
diff options
context:
space:
mode:
authorredmatrix <git@macgirvin.com>2016-04-08 04:44:10 -0700
committerredmatrix <git@macgirvin.com>2016-04-08 04:44:10 -0700
commit9b66b5eee37c1a3958d9ddccb9c1a06ac7ef49ce (patch)
tree55a9d412ca70f40e1634413bbe2bf53ce9a4fc42 /Zotlabs/Web/SessionHandler.php
parent2db59f3b7697d141e6dda0aa85f9161bfee32a2a (diff)
downloadvolse-hubzilla-9b66b5eee37c1a3958d9ddccb9c1a06ac7ef49ce.tar.gz
volse-hubzilla-9b66b5eee37c1a3958d9ddccb9c1a06ac7ef49ce.tar.bz2
volse-hubzilla-9b66b5eee37c1a3958d9ddccb9c1a06ac7ef49ce.zip
objectify all the session management stuff
Diffstat (limited to 'Zotlabs/Web/SessionHandler.php')
-rw-r--r--Zotlabs/Web/SessionHandler.php78
1 files changed, 78 insertions, 0 deletions
diff --git a/Zotlabs/Web/SessionHandler.php b/Zotlabs/Web/SessionHandler.php
new file mode 100644
index 000000000..ede2bd609
--- /dev/null
+++ b/Zotlabs/Web/SessionHandler.php
@@ -0,0 +1,78 @@
+<?php
+
+namespace Zotlabs\Web;
+
+
+class SessionHandler implements \SessionHandlerInterface {
+
+ private $session_exists;
+ private $session_expire;
+
+
+ function open ($s, $n) {
+ $this->session_exists = 0;
+ $this->session_expire = 180000;
+ return true;
+ }
+
+ function read ($id) {
+
+ if(x($id))
+ $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
+
+ if($r) {
+ $this->session_exists = true;
+ return $r[0]['data'];
+ }
+
+ return '';
+ }
+
+
+ function write ($id, $data) {
+
+ if(! $id || ! $data) {
+ return false;
+ }
+
+ $expire = time() + $this->session_expire;
+ $default_expire = time() + 300;
+
+ if($this->session_exists) {
+ q("UPDATE `session`
+ SET `data` = '%s', `expire` = '%s' WHERE `sid` = '%s'",
+ dbesc($data),
+ dbesc($expire),
+ dbesc($id)
+ );
+ }
+ else {
+ q("INSERT INTO `session` (sid, expire, data) values ('%s', '%s', '%s')",
+ dbesc($id),
+ dbesc($default_expire),
+ dbesc($data)
+ );
+ }
+
+ return true;
+ }
+
+
+ function close() {
+ return true;
+ }
+
+
+ function destroy ($id) {
+ q("DELETE FROM `session` WHERE `sid` = '%s'", dbesc($id));
+ return true;
+ }
+
+
+ function gc($expire) {
+ q("DELETE FROM session WHERE expire < %d", dbesc(time()));
+ return true;
+ }
+
+
+} \ No newline at end of file