]>
git.wh0rd.org - tt-rss.git/blob - sessions.php
2 // Original from http://www.daniweb.com/code/snippet43.html
4 require_once "config.php";
7 $session_expire = SESSION_EXPIRE_TIME
; //seconds
9 ini_set("session.gc_probability", 50);
10 ini_set("session.name", "ttrss_sid");
11 ini_set("session.use_only_cookies", true);
13 function open ($s, $n) {
15 global $session_connection;
17 $session_connection = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
24 global $session_connection,$session_read;
26 $ip_address = $_SERVER["REMOTE_ADDR"];
28 if (SESSION_CHECK_ADDRESS
) {
29 $address_check_qpart = " AND ip_address = '$ip_address'";
32 $query = "SELECT data FROM ttrss_sessions WHERE id='$id' $address_check_qpart";
34 $res = db_query($session_connection, $query);
36 if (db_num_rows($res) != 1) {
39 $session_read = db_fetch_assoc($res);
40 $session_read["data"] = base64_decode($session_read["data"]);
41 return $session_read["data"];
45 function write ($id, $data) {
51 global $session_connection, $session_read, $session_expire;
53 $expire = time() +
$session_expire;
55 $data = db_escape_string(base64_encode($data), $session_connection);
57 $ip_address = $_SERVER["REMOTE_ADDR"];
59 if (SESSION_CHECK_ADDRESS
) {
60 $address_check_qpart = " AND ip_address = '$ip_address'";
64 $query = "UPDATE ttrss_sessions SET data='$data',
65 expire='$expire' WHERE id='$id' $address_check_qpart";
67 $query = "INSERT INTO ttrss_sessions (id, data, expire, ip_address)
68 VALUES ('$id', '$data', '$expire', '$ip_address')";
71 db_query($session_connection, $query);
77 global $session_connection;
79 db_close($session_connection);
84 function destroy ($id) {
86 global $session_connection;
88 $ip_address = $_SERVER["REMOTE_ADDR"];
90 if (SESSION_CHECK_ADDRESS
) {
91 $address_check_qpart = " AND ip_address = '$ip_address'";
94 $query = "DELETE FROM ttrss_sessions WHERE id = '$id' $address_check_qpart";
96 db_query($session_connection, $query);
101 function gc ($expire) {
103 global $session_connection;
105 $query = "DELETE FROM ttrss_sessions WHERE expire < " . time();
107 db_query($session_connection, $query);
110 // session_set_cookie_params(SESSION_COOKIE_LIFETIME);
112 if (DATABASE_BACKED_SESSIONS
) {
113 session_set_save_handler("open", "close", "read", "write", "destroy", "gc");