diff options
author | Andrew Dolgov <[email protected]> | 2006-03-02 09:10:43 +0100 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2006-03-02 09:10:43 +0100 |
commit | 36bfab86c2682c460b197029bbae4daa6ff83ec4 (patch) | |
tree | d243e8863dd358be04b3695c0b092287657452b7 | |
parent | 36ae0574dd83d660570574ecc40d0d847dbde897 (diff) |
database backed sessions
-rw-r--r-- | backend.php | 4 | ||||
-rw-r--r-- | db-prefs.php | 4 | ||||
-rw-r--r-- | login.php | 2 | ||||
-rw-r--r-- | logout.php | 2 | ||||
-rw-r--r-- | opml.php | 2 | ||||
-rw-r--r-- | prefs.php | 2 | ||||
-rw-r--r-- | schema/ttrss_schema_mysql.sql | 8 | ||||
-rw-r--r-- | schema/ttrss_schema_pgsql.sql | 9 | ||||
-rw-r--r-- | schema/upgrade-1.1.3-1.1.4-mysql.sql | 7 | ||||
-rw-r--r-- | schema/upgrade-1.1.3-1.1.4-pgsql.sql | 8 | ||||
-rw-r--r-- | sessions.php | 92 | ||||
-rw-r--r-- | stats.php | 2 | ||||
-rw-r--r-- | tt-rss.php | 2 | ||||
-rw-r--r-- | utils/xml-export.php | 2 | ||||
-rw-r--r-- | utils/xml-import.php | 4 |
15 files changed, 137 insertions, 13 deletions
diff --git a/backend.php b/backend.php index 2fd8fe22d..c5ce040ca 100644 --- a/backend.php +++ b/backend.php @@ -1,6 +1,6 @@ <? - session_start(); - + require_once "sessions.php"; + header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Expires: -1"); diff --git a/db-prefs.php b/db-prefs.php index 80d890fbc..8714e340c 100644 --- a/db-prefs.php +++ b/db-prefs.php @@ -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(); } @@ -1,5 +1,5 @@ <? - session_start(); + require_once "sessions.php"; require_once "sanity_check.php"; require_once "version.php"; diff --git a/logout.php b/logout.php index b258067a6..056cc025d 100644 --- a/logout.php +++ b/logout.php @@ -1,5 +1,5 @@ <? - session_start(); + require_once "sessions.php"; require_once "config.php"; require_once "functions.php"; @@ -1,5 +1,5 @@ <? - session_start(); + require_once "sessions.php"; require_once "sanity_check.php"; require_once "functions.php"; @@ -1,5 +1,5 @@ <? - session_start(); + require_once "sessions.php"; require_once "sanity_check.php"; require_once "version.php"; diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql index eb1076999..5032334c8 100644 --- a/schema/ttrss_schema_mysql.sql +++ b/schema/ttrss_schema_mysql.sql @@ -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; diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql index 97434ce2a..ec98bbb22 100644 --- a/schema/ttrss_schema_pgsql.sql +++ b/schema/ttrss_schema_pgsql.sql @@ -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; diff --git a/schema/upgrade-1.1.3-1.1.4-mysql.sql b/schema/upgrade-1.1.3-1.1.4-mysql.sql index 2570bb4ba..f2e9bd16c 100644 --- a/schema/upgrade-1.1.3-1.1.4-mysql.sql +++ b/schema/upgrade-1.1.3-1.1.4-mysql.sql @@ -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; diff --git a/schema/upgrade-1.1.3-1.1.4-pgsql.sql b/schema/upgrade-1.1.3-1.1.4-pgsql.sql index 92025c4af..6a0f46b55 100644 --- a/schema/upgrade-1.1.3-1.1.4-pgsql.sql +++ b/schema/upgrade-1.1.3-1.1.4-pgsql.sql @@ -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 index 000000000..dddab5012 --- /dev/null +++ b/sessions.php @@ -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(); +?> @@ -1,5 +1,5 @@ <? - session_start(); + require_once "sessions.php"; require_once "sanity_check.php"; require_once "version.php"; diff --git a/tt-rss.php b/tt-rss.php index 82ba8a895..9d125614d 100644 --- a/tt-rss.php +++ b/tt-rss.php @@ -1,5 +1,5 @@ <? - session_start(); + require_once "sessions.php"; require_once "sanity_check.php"; require_once "version.php"; diff --git a/utils/xml-export.php b/utils/xml-export.php index a10c9e3de..438f008d4 100644 --- a/utils/xml-export.php +++ b/utils/xml-export.php @@ -1,5 +1,5 @@ <? - session_start(); + require_once "sessions.php"; define('MAX_SCHEMA_VERSION', 5); diff --git a/utils/xml-import.php b/utils/xml-import.php index aeccd77e4..0706b0fa2 100644 --- a/utils/xml-import.php +++ b/utils/xml-import.php @@ -1,6 +1,6 @@ <? - session_start(); - + require_once "sessions.php"; + require_once "config.php"; require_once "functions.php"; require_once "db.php"; |