Improve persistent sessions
This commit is contained in:
parent
97480fd46f
commit
9e80ce02b1
1 changed files with 14 additions and 21 deletions
11
index.php
11
index.php
|
@ -88,10 +88,7 @@ if (
|
||||||
/**
|
/**
|
||||||
* Persistent (stay logged in)
|
* Persistent (stay logged in)
|
||||||
*/
|
*/
|
||||||
if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database) {
|
if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database && !$_SESSION['user']->isLoggedIn()) {
|
||||||
$table_sessions_exists = $database->tableExists('sessions');
|
|
||||||
|
|
||||||
if ($table_sessions_exists) {
|
|
||||||
$sessions = $database
|
$sessions = $database
|
||||||
->query(
|
->query(
|
||||||
'SELECT *
|
'SELECT *
|
||||||
|
@ -101,11 +98,8 @@ if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database) {
|
||||||
->fetchAll();
|
->fetchAll();
|
||||||
|
|
||||||
if (false !== $sessions) {
|
if (false !== $sessions) {
|
||||||
$_SESSION['user'] = new User();
|
|
||||||
|
|
||||||
foreach ($sessions as $session) {
|
foreach ($sessions as $session) {
|
||||||
/** Column sessions.expires was added in v0.7.1. */
|
$expires = strtotime($session['expires']);
|
||||||
$expires = strtotime($session['expires'] ?? date('Y-m-d H:i:s', time() + 1));
|
|
||||||
|
|
||||||
if (time() < $expires) {
|
if (time() < $expires) {
|
||||||
$_SESSION['user'] = User::getFromID($session['user']);
|
$_SESSION['user'] = User::getFromID($session['user']);
|
||||||
|
@ -114,7 +108,6 @@ if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue