diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index 1e5d0c4f171..cc86f6f3ce8 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -832,7 +832,7 @@ function session_create($user_id = false, $set_admin = false, $persist_login = f // Update the form key $sql = 'UPDATE ' . USERS_TABLE . ' SET user_form_salt = \'' . $db->sql_escape($this->data['user_form_salt']) . '\', - user_last_active = ' . (int) $this->data['session_time'] . ' + user_last_active = ' . (int) $this->time_now . ' WHERE user_id = ' . (int) $this->data['user_id']; $db->sql_query($sql); } @@ -980,8 +980,8 @@ function session_gc() } /** - * Get most recent session for each registered user to sync user last visit with it - * Inner SELECT gets most recent sessions for each unique session_user_id + * Get expired sessions for registered users, only most recent for each user + * Inner SELECT gets most recent expired sessions for unique session_user_id * Outer SELECT gets data for them */ $sql_select = 'SELECT s1.session_page, s1.session_user_id, s1.session_time AS recent_time @@ -989,7 +989,8 @@ function session_gc() INNER JOIN ( SELECT session_user_id, MAX(session_time) AS recent_time FROM ' . SESSIONS_TABLE . ' - WHERE session_user_id <> ' . ANONYMOUS . ' + WHERE session_time < ' . ($this->time_now - (int) $config['session_length']) . ' + AND session_user_id <> ' . ANONYMOUS . ' GROUP BY session_user_id ) AS s2 ON s1.session_user_id = s2.session_user_id