fixed the custom session system

This commit is contained in:
Louis Vallat 2019-11-10 15:36:37 +01:00
parent 35f1a02db4
commit 7fb7758df2

View File

@ -26,7 +26,7 @@ function connect_user($user_id, $long_expiration = true)
global $PDO, $SESSION_COOKIE_NAME, $MAX_COOKIE_LIFE; global $PDO, $SESSION_COOKIE_NAME, $MAX_COOKIE_LIFE;
// Set an expiration delay for the cookie // Set an expiration delay for the cookie
$delay = 0; $delay = 86400;
if ($long_expiration === true) { if ($long_expiration === true) {
$delay = $MAX_COOKIE_LIFE; $delay = $MAX_COOKIE_LIFE;
} }
@ -39,24 +39,17 @@ function connect_user($user_id, $long_expiration = true)
$query = $PDO->prepare($sql); $query = $PDO->prepare($sql);
$query->bindValue(":user_id", $user_id); $query->bindValue(":user_id", $user_id);
if ($long_expiration === true) { $query->bindValue(
$query->bindValue( ":connection_eol",
":connection_eol", date('Y-m-d H:i:s', strtotime("now + $delay seconds")), PDO::PARAM_STR
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(":session_id", $session_id); $query->bindValue(":session_id", $session_id);
if ($query->execute()) { if ($query->execute()) {
return setcookie( return setcookie(
$SESSION_COOKIE_NAME, $SESSION_COOKIE_NAME,
$session_id, $session_id,
$delay, time() + $delay,
$secure = true $secure = true
); );
} }
@ -67,7 +60,7 @@ function clean_old_sessions()
{ {
global $PDO; global $PDO;
$sql = "DELETE FROM sessions WHERE connection_eol > CURRENT_TIMESTAMP();"; $sql = "DELETE FROM sessions WHERE connection_eol < CURRENT_TIMESTAMP();";
$query = $PDO->prepare($sql); $query = $PDO->prepare($sql);
return $query->execute(); return $query->execute();
} }