]>
git.wh0rd.org - tt-rss.git/blob - classes/sessionhandler.php
2 class SessionHandler
implements SessionHandlerInterface
{
3 private static $instance;
6 public static function get() {
7 if (self
::$instance == null)
8 self
::$instance = new self();
10 return self
::$instance;
13 private function __construct() {
14 $this->db
= Db
::get();
16 session_set_save_handler("SessionHandler::open", "SessionHandler::close",
17 "SessionHandler::read", "SessionHandler::write", "SessionHandler::destroy",
18 "SessionHandler::gc");
21 public static function open($save_path, $name) { }
24 public static function read ($id){
26 $query = "SELECT data FROM ttrss_sessions WHERE id='$id'";
28 $res = $this->db
->query("SELECT data FROM ttrss_sessions WHERE id='$id'");
30 if ($this->db
->num_rows($res) != 1) {
32 "INSERT INTO ttrss_sessions (id, data, expire)
33 VALUES ('$id', '$data', '$expire')";
38 $data = $this->db
->fetch_result($res, 0, "data");
39 return base64_decode($data);
44 public static function write($id, $data) {
49 $data = $this->db
->escape_string( base64_encode($data), false);
51 $expire = time() +
max(SESSION_COOKIE_LIFETIME
, 86400);
53 $query = "UPDATE ttrss_sessions SET data='$data',
54 expire = '$expire' WHERE id='$id'";
56 $this->db
->query( $query);
60 public static function close () { }
62 public static function destroy($session_id) {
63 $this->db
->query("DELETE FROM ttrss_sessions WHERE id = '$session_id'");
67 public static function gc($maxLifeTime) {
68 $this->db
->query("DELETE FROM ttrss_sessions WHERE expire < " time() - $maxLifeTime);