fixed the custom session system
This commit is contained in:
parent
35f1a02db4
commit
7fb7758df2
@ -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"))
|
||||
))
|
||||
date('Y-m-d H:i:s', strtotime("now + $delay seconds")), PDO::PARAM_STR
|
||||
);
|
||||
} else {
|
||||
$query->bindValue(":connection_eol", null, PDO::PARAM_INT);
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user