From 7fb7758df21a68878356d29217ed537af8ad6e3e Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Sun, 10 Nov 2019 15:36:37 +0100 Subject: [PATCH] fixed the custom session system --- assets/php/utils.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/assets/php/utils.php b/assets/php/utils.php index c332f0c..b5e2ad1 100644 --- a/assets/php/utils.php +++ b/assets/php/utils.php @@ -26,7 +26,7 @@ function connect_user($user_id, $long_expiration = true) global $PDO, $SESSION_COOKIE_NAME, $MAX_COOKIE_LIFE; // Set an expiration delay for the cookie - $delay = 0; + $delay = 86400; if ($long_expiration === true) { $delay = $MAX_COOKIE_LIFE; } @@ -39,24 +39,17 @@ function connect_user($user_id, $long_expiration = true) $query = $PDO->prepare($sql); $query->bindValue(":user_id", $user_id); - if ($long_expiration === true) { - $query->bindValue( - ":connection_eol", - date('Y-m-d H:i:s', strtotime( - "$MAX_COOKIE_LIFE seconds", - strtotime(date("Y-m-d H:i:s")) - )) - ); - } else { - $query->bindValue(":connection_eol", null, PDO::PARAM_INT); - } + $query->bindValue( + ":connection_eol", + date('Y-m-d H:i:s', strtotime("now + $delay seconds")), PDO::PARAM_STR + ); $query->bindValue(":session_id", $session_id); if ($query->execute()) { return setcookie( $SESSION_COOKIE_NAME, $session_id, - $delay, + time() + $delay, $secure = true ); } @@ -67,7 +60,7 @@ function clean_old_sessions() { global $PDO; - $sql = "DELETE FROM sessions WHERE connection_eol > CURRENT_TIMESTAMP();"; + $sql = "DELETE FROM sessions WHERE connection_eol < CURRENT_TIMESTAMP();"; $query = $PDO->prepare($sql); return $query->execute(); }