2 // Original from http://www.daniweb.com/code/snippet43.html
4 require_once "config.php";
7 $session_expire = SESSION_EXPIRE_TIME; //seconds
8 $session_name = (!defined('TTRSS_SESSION_NAME')) ? "ttrss_sid" : TTRSS_SESSION_NAME;
10 ini_set("session.gc_probability", 50);
11 ini_set("session.name", $session_name);
12 ini_set("session.use_only_cookies", true);
13 ini_set("session.gc_maxlifetime", SESSION_EXPIRE_TIME);
15 function open ($s, $n) {
17 global $session_connection;
19 $session_connection = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
26 global $session_connection,$session_read;
28 $query = "SELECT data FROM ttrss_sessions WHERE id='$id' $address_check_qpart";
30 $res = db_query($session_connection, $query);
32 if (db_num_rows($res) != 1) {
35 $session_read = db_fetch_assoc($res);
36 $session_read["data"] = base64_decode($session_read["data"]);
37 return $session_read["data"];
41 function write ($id, $data) {
47 global $session_connection, $session_read, $session_expire;
49 $expire = time() + $session_expire;
51 $data = db_escape_string(base64_encode($data), $session_connection);
54 $query = "UPDATE ttrss_sessions SET data='$data',
55 expire='$expire' WHERE id='$id' $address_check_qpart";
57 $query = "INSERT INTO ttrss_sessions (id, data, expire)
58 VALUES ('$id', '$data', '$expire')";
61 db_query($session_connection, $query);
67 global $session_connection;
69 db_close($session_connection);
74 function destroy ($id) {
76 global $session_connection;
78 $query = "DELETE FROM ttrss_sessions WHERE id = '$id' $address_check_qpart";
80 db_query($session_connection, $query);
85 function gc ($expire) {
87 global $session_connection;
89 $query = "DELETE FROM ttrss_sessions WHERE expire < " . time();
91 db_query($session_connection, $query);
94 if (DATABASE_BACKED_SESSIONS) {
95 session_set_save_handler("open", "close", "read", "write", "destroy", "gc");
98 session_set_cookie_params(SESSION_COOKIE_LIFETIME);