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