]> git.wh0rd.org Git - tt-rss.git/commitdiff
database backed sessions
authorAndrew Dolgov <fox@madoka.spb.ru>
Thu, 2 Mar 2006 08:10:43 +0000 (09:10 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Thu, 2 Mar 2006 08:10:43 +0000 (09:10 +0100)
15 files changed:
backend.php
db-prefs.php
login.php
logout.php
opml.php
prefs.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/upgrade-1.1.3-1.1.4-mysql.sql
schema/upgrade-1.1.3-1.1.4-pgsql.sql
sessions.php [new file with mode: 0644]
stats.php
tt-rss.php
utils/xml-export.php
utils/xml-import.php

index 2fd8fe22dd379fcfac86e5bfe343c484d6b5b20e..c5ce040ca339c8a0d025c0e17db9091dda7dd23b 100644 (file)
@@ -1,6 +1,6 @@
 <?
-       session_start();
-
+       require_once "sessions.php";
+       
        header("Cache-Control: no-cache, must-revalidate");
        header("Pragma: no-cache");
        header("Expires: -1");
index 80d890fbc249973e03e068c1da85d7cf5bcb20c2..8714e340cafd0688ef8ab2941c9a101bf9ad5326 100644 (file)
@@ -3,8 +3,8 @@
        require_once "db.php";
 
        if (! DISABLE_SESSIONS) {       
-               session_start();
-               
+               require_once "sessions.php";
+       
                if (!$_SESSION["prefs_cache"])
                        $_SESSION["prefs_cache"] = array();
        }
index eda2ac826a53324f32d9e5c84e70e83c9896f226..bfdce9a6dc00c7640e3dbeeecfd169411be60cdc 100644 (file)
--- a/login.php
+++ b/login.php
@@ -1,5 +1,5 @@
 <?
-       session_start();
+       require_once "sessions.php";
 
        require_once "sanity_check.php";
        require_once "version.php"; 
index b258067a6a83010122ba4d448e4382835adaec13..056cc025dce29f3038e3ac067992f8a4fbe7b961 100644 (file)
@@ -1,5 +1,5 @@
 <?
-       session_start();
+       require_once "sessions.php";
 
        require_once "config.php";
        require_once "functions.php";
index 23a28277662d892ab45489a5def559eef1702bba..492a8b8cb19d597d375c7b29f94fcc42db07f32a 100644 (file)
--- a/opml.php
+++ b/opml.php
@@ -1,5 +1,5 @@
 <?
-       session_start();
+       require_once "sessions.php";
 
        require_once "sanity_check.php";
        require_once "functions.php";
index 988367861ea17043ed29e896cd182f016ef9890f..7dd81e2bf6297139d8fb834cf598a9ad1beabbad 100644 (file)
--- a/prefs.php
+++ b/prefs.php
@@ -1,5 +1,5 @@
 <?
-       session_start();
+       require_once "sessions.php";
 
        require_once "sanity_check.php";
        require_once "version.php"; 
index eb10769991a889a7a785e4e8207fe7835175ef56..5032334c82b2f91758f8ec9f8dad9e265da3bc44 100644 (file)
@@ -16,6 +16,7 @@ drop table if exists ttrss_feeds;
 drop table if exists ttrss_feed_categories;
 drop table if exists ttrss_users;
 drop table if exists ttrss_themes;
+drop table if exists ttrss_sessions;
 
 begin;
 
@@ -255,4 +256,11 @@ create table ttrss_scheduled_updates (id integer not null primary key auto_incre
        foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE,
        foreign key (feed_id) references ttrss_feeds(id) ON DELETE CASCADE) TYPE=InnoDB;
 
+create table ttrss_sessions (int_id integer not null primary key auto_increment,
+       id varchar(300) unique not null,
+       data text,
+       expire integer not null,
+       index (id), 
+       index (expire)) TYPE=InnoDB;
+
 commit;
index 97434ce2a1fff51efcc00e3583520a832d1c4160..ec98bbb22f463b2b62cb93365cc8b468af198503 100644 (file)
@@ -16,6 +16,7 @@ drop table ttrss_feeds;
 drop table ttrss_feed_categories;
 drop table ttrss_users;
 drop table ttrss_themes;
+drop table ttrss_sessions;
 
 begin;
 
@@ -230,4 +231,12 @@ create table ttrss_scheduled_updates (id serial not null primary key,
        feed_id integer default null references ttrss_feeds(id) ON DELETE CASCADE,
        entered timestamp not null default NOW());
 
+create table ttrss_sessions (int_id serial not null primary key,
+               id varchar(300) unique not null,
+               data text,
+               expire integer not null);
+
+create index ttrss_sessions_id_index on ttrss_sessions(id);
+create index ttrss_sessions_expire_index on ttrss_sessions(expire);
+
 commit;
index 2570bb4bad1fe09b94c6e112205d07b98ea00faf..f2e9bd16c27fdd944265bccbdcc361b7a7988b4a 100644 (file)
@@ -5,5 +5,12 @@ update ttrss_entries set author = '';
 alter table ttrss_entries change author author varchar(250) not null;
 alter table ttrss_entries alter column author set default '';
 
+create table ttrss_sessions (int_id integer not null primary key auto_increment,
+       id varchar(300) unique not null,
+       data text,
+       expire integer not null,
+       index (id), 
+       index (expire)) TYPE=InnoDB;
+
 update ttrss_version set schema_version = 6;
 
index 92025c4af05a057735ac20252cbf5f5f0ccf9c41..6a0f46b555662f969138df479dc00f908b338970 100644 (file)
@@ -7,6 +7,14 @@ update ttrss_entries set author = '';
 alter table ttrss_entries alter column author set not null;
 alter table ttrss_entries alter column author set default '';
 
+create table ttrss_sessions (int_id serial not null primary key,
+               id varchar(300) unique not null,
+               data text,
+               expire integer not null);
+
+create index ttrss_sessions_id_index on ttrss_sessions(id);
+create index ttrss_sessions_expire_index on ttrss_sessions(expire);
+
 update ttrss_version set schema_version = 6;
 
 commit;
diff --git a/sessions.php b/sessions.php
new file mode 100644 (file)
index 0000000..dddab50
--- /dev/null
@@ -0,0 +1,92 @@
+<?
+       // Original from http://www.daniweb.com/code/snippet43.html
+
+       require_once "config.php";
+       require_once "db.php";
+
+       $session_expire = 600;
+
+       ini_set("session.gc_probability", 50);
+
+       function open ($s, $n) {
+       
+               global $session_connection;
+               
+               $session_connection = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
+               
+               return true;
+       }
+
+       function read ($id){
+       
+               global $session_connection,$session_read;                                        
+
+               $query = "SELECT data FROM ttrss_sessions WHERE id='$id'";
+
+               $res = db_query($session_connection, $query);
+               
+               if (db_num_rows($res) != 1) {
+                       return "";
+               } else {
+                       $session_read = db_fetch_assoc($res);
+                       $session_read["data"] = base64_decode($session_read["data"]);
+                       return $session_read["data"];
+               }
+       }
+
+       function write ($id, $data) {
+               if (! $data) { 
+                       return false; 
+               }
+               
+               global $session_connection, $session_read, $session_expire;
+               
+               $expire = time() + $session_expire;
+               
+               $data = db_escape_string(base64_encode($data), $session_connection);
+               
+               if ($session_read) {
+                       $query = "UPDATE ttrss_sessions SET data='$data', 
+                                       expire='$expire' WHERE id='$id'"; 
+               } else {
+                       $query = "INSERT INTO ttrss_sessions (id, data, expire)
+                                       VALUES ('$id', '$data', '$expire')";
+               }
+               
+               db_query($session_connection, $query);
+               return true;
+       }
+
+       function close () {
+       
+               global $session_connection;
+               
+               db_close($session_connection);
+               
+               return true;
+       }
+
+       function destroy ($id) {
+       
+               global $session_connection;
+               
+               $query = "DELETE FROM ttrss_sessions WHERE id = '$id'";
+               
+               db_query($session_connection, $query);
+               
+               return true;
+       }
+
+       function gc ($expire) {
+       
+               global $session_connection;
+               
+               $query = "DELETE FROM ttrss_sessions WHERE expire < " . time();
+               
+               db_query($session_connection, $query);
+       }
+
+       session_set_save_handler ("open", "close", "read", "write", "destroy", "gc");
+       session_start();
+?>
index d56389ecab6a02cb374ef3eff752b0a3c0c77448..007053b18567142750757bc4c53b9b8ff09b001a 100644 (file)
--- a/stats.php
+++ b/stats.php
@@ -1,5 +1,5 @@
 <?
-       session_start();
+       require_once "sessions.php";
 
        require_once "sanity_check.php";
        require_once "version.php"; 
index 82ba8a895aaf600e82d58c07c428a88aaee08702..9d125614dd95c053a84fe757575a8e611c83cc1f 100644 (file)
@@ -1,5 +1,5 @@
 <?
-       session_start();
+       require_once "sessions.php";
 
        require_once "sanity_check.php";
        require_once "version.php"; 
index a10c9e3dea6de9631432b09f4b5acbb63d9aeb7a..438f008d419ddd2ee85de0af6a27a9bdf9bd9129 100644 (file)
@@ -1,5 +1,5 @@
 <?
-       session_start();
+       require_once "sessions.php";
 
        define('MAX_SCHEMA_VERSION', 5);
 
index aeccd77e42425f592db85486268eb7185e45be18..0706b0fa2a346f98ca59faf23c868460196e11a2 100644 (file)
@@ -1,6 +1,6 @@
 <?
-       session_start();
-
+       require_once "sessions.php";
+       
        require_once "config.php";
        require_once "functions.php";
        require_once "db.php";