|
|
@ -1,4 +1,6 @@
|
|
|
|
<?php
|
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sessions;
|
|
|
|
|
|
|
|
|
|
|
|
// Original from http://www.daniweb.com/code/snippet43.html
|
|
|
|
// Original from http://www.daniweb.com/code/snippet43.html
|
|
|
|
|
|
|
|
|
|
|
|
require_once "config.php";
|
|
|
|
require_once "config.php";
|
|
|
@ -23,7 +25,7 @@
|
|
|
|
global $schema_version;
|
|
|
|
global $schema_version;
|
|
|
|
|
|
|
|
|
|
|
|
if (!$schema_version) {
|
|
|
|
if (!$schema_version) {
|
|
|
|
$row = Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch();
|
|
|
|
$row = \Db::pdo()->query("SELECT schema_version FROM ttrss_version")->fetch();
|
|
|
|
|
|
|
|
|
|
|
|
$version = $row["schema_version"];
|
|
|
|
$version = $row["schema_version"];
|
|
|
|
|
|
|
|
|
|
|
@ -42,7 +44,7 @@
|
|
|
|
__("Session failed to validate (schema version changed)");
|
|
|
|
__("Session failed to validate (schema version changed)");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pdo = Db::pdo();
|
|
|
|
$pdo = \Db::pdo();
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($_SESSION["uid"])) {
|
|
|
|
if (!empty($_SESSION["uid"])) {
|
|
|
|
|
|
|
|
|
|
|
@ -85,7 +87,7 @@
|
|
|
|
function ttrss_read ($id){
|
|
|
|
function ttrss_read ($id){
|
|
|
|
global $session_expire;
|
|
|
|
global $session_expire;
|
|
|
|
|
|
|
|
|
|
|
|
$sth = Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?");
|
|
|
|
$sth = \Db::pdo()->prepare("SELECT data FROM ttrss_sessions WHERE id=?");
|
|
|
|
$sth->execute([$id]);
|
|
|
|
$sth->execute([$id]);
|
|
|
|
|
|
|
|
|
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
if ($row = $sth->fetch()) {
|
|
|
@ -94,7 +96,7 @@
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$expire = time() + $session_expire;
|
|
|
|
$expire = time() + $session_expire;
|
|
|
|
|
|
|
|
|
|
|
|
$sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire)
|
|
|
|
$sth = \Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire)
|
|
|
|
VALUES (?, '', ?)");
|
|
|
|
VALUES (?, '', ?)");
|
|
|
|
$sth->execute([$id, $expire]);
|
|
|
|
$sth->execute([$id, $expire]);
|
|
|
|
|
|
|
|
|
|
|
@ -110,14 +112,14 @@
|
|
|
|
$data = base64_encode($data);
|
|
|
|
$data = base64_encode($data);
|
|
|
|
$expire = time() + $session_expire;
|
|
|
|
$expire = time() + $session_expire;
|
|
|
|
|
|
|
|
|
|
|
|
$sth = Db::pdo()->prepare("SELECT id FROM ttrss_sessions WHERE id=?");
|
|
|
|
$sth = \Db::pdo()->prepare("SELECT id FROM ttrss_sessions WHERE id=?");
|
|
|
|
$sth->execute([$id]);
|
|
|
|
$sth->execute([$id]);
|
|
|
|
|
|
|
|
|
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
$sth = Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?");
|
|
|
|
$sth = \Db::pdo()->prepare("UPDATE ttrss_sessions SET data=?, expire=? WHERE id=?");
|
|
|
|
$sth->execute([$data, $expire, $id]);
|
|
|
|
$sth->execute([$data, $expire, $id]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
$sth = Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire)
|
|
|
|
$sth = \Db::pdo()->prepare("INSERT INTO ttrss_sessions (id, data, expire)
|
|
|
|
VALUES (?, ?, ?)");
|
|
|
|
VALUES (?, ?, ?)");
|
|
|
|
$sth->execute([$id, $data, $expire]);
|
|
|
|
$sth->execute([$id, $data, $expire]);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -130,22 +132,23 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ttrss_destroy($id) {
|
|
|
|
function ttrss_destroy($id) {
|
|
|
|
$sth = Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?");
|
|
|
|
$sth = \Db::pdo()->prepare("DELETE FROM ttrss_sessions WHERE id = ?");
|
|
|
|
$sth->execute([$id]);
|
|
|
|
$sth->execute([$id]);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function ttrss_gc ($expire) {
|
|
|
|
function ttrss_gc ($expire) {
|
|
|
|
Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time());
|
|
|
|
\Db::pdo()->query("DELETE FROM ttrss_sessions WHERE expire < " . time());
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!SINGLE_USER_MODE /* && DB_TYPE == "pgsql" */) {
|
|
|
|
if (!SINGLE_USER_MODE /* && DB_TYPE == "pgsql" */) {
|
|
|
|
session_set_save_handler("ttrss_open",
|
|
|
|
session_set_save_handler('\Sessions\ttrss_open',
|
|
|
|
"ttrss_close", "ttrss_read", "ttrss_write",
|
|
|
|
'\Sessions\ttrss_close', '\Sessions\ttrss_read',
|
|
|
|
"ttrss_destroy", "ttrss_gc");
|
|
|
|
'\Sessions\ttrss_write', '\Sessions\ttrss_destroy',
|
|
|
|
|
|
|
|
'\Sessions\ttrss_gc');
|
|
|
|
register_shutdown_function('session_write_close');
|
|
|
|
register_shutdown_function('session_write_close');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|