mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
logout.php: Pull out DB code
* Move DB code for removing a session in logout.php to a new function in acctfuncs.inc.php * Add ability for clear_expired_sessions function to check for DB connection * Centralization of DB code important in a future transition to PDO interface Signed-off-by: canyonknight <canyonknight@gmail.com> Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
parent
d3de667901
commit
f93f1a652f
2 changed files with 20 additions and 5 deletions
|
@ -10,10 +10,10 @@ include_once("acctfuncs.inc.php"); # access AUR common functions
|
||||||
# sending any HTML output.
|
# sending any HTML output.
|
||||||
#
|
#
|
||||||
if (isset($_COOKIE["AURSID"])) {
|
if (isset($_COOKIE["AURSID"])) {
|
||||||
|
if (!$dbh) {
|
||||||
$dbh = db_connect();
|
$dbh = db_connect();
|
||||||
$q = "DELETE FROM Sessions WHERE SessionID = '";
|
}
|
||||||
$q.= db_escape_string($_COOKIE["AURSID"]) . "'";
|
delete_session_id($_COOKIE["AURSID"], $dbh);
|
||||||
db_query($q, $dbh);
|
|
||||||
# setting expiration to 1 means '1 second after midnight January 1, 1970'
|
# setting expiration to 1 means '1 second after midnight January 1, 1970'
|
||||||
setcookie("AURSID", "", 1, "/", null, !empty($_SERVER['HTTPS']), true);
|
setcookie("AURSID", "", 1, "/", null, !empty($_SERVER['HTTPS']), true);
|
||||||
unset($_COOKIE['AURSID']);
|
unset($_COOKIE['AURSID']);
|
||||||
|
|
|
@ -681,10 +681,25 @@ function user_is_privileged($id, $dbh) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Remove session on logout
|
||||||
|
function delete_session_id($sid, $dbh=NULL) {
|
||||||
|
if(!$dbh) {
|
||||||
|
$dbh = db_connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
$q = "DELETE FROM Sessions WHERE SessionID = '";
|
||||||
|
$q.= db_escape_string($sid) . "'";
|
||||||
|
db_query($q, $dbh);
|
||||||
|
}
|
||||||
|
|
||||||
# Clear out old expired sessions.
|
# Clear out old expired sessions.
|
||||||
function clear_expired_sessions( $dbh ) {
|
function clear_expired_sessions($dbh=NULL) {
|
||||||
global $LOGIN_TIMEOUT;
|
global $LOGIN_TIMEOUT;
|
||||||
|
|
||||||
|
if(!$dbh) {
|
||||||
|
$dbh = db_connect();
|
||||||
|
}
|
||||||
|
|
||||||
$q = "DELETE FROM Sessions WHERE LastUpdateTS < (UNIX_TIMESTAMP() - $LOGIN_TIMEOUT)";
|
$q = "DELETE FROM Sessions WHERE LastUpdateTS < (UNIX_TIMESTAMP() - $LOGIN_TIMEOUT)";
|
||||||
db_query($q, $dbh);
|
db_query($q, $dbh);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue