If, for example:
- Php stores sessions for 2 hours (php.ini - session maxlifetime)
- Your app will logout users, if they dont do anything on site for 1 hour
Then, in order to display message like 'You've been logout due inactivity', you will need something like this:
const NOT_LOGGED_IN = null, MANUAL = 1, INACTIVITY = 2;
public function logout() {
$user = $this->session->get('user-secret-info');
$user->authenticated = false;
$user->reason = self::MANUAL; // Means, that user logout by himself
// Dont forget to save session
$this->sesssion->set('user-secret-info', $user);
}
pubcic function isLoggedIn() {
$user = $this->session->get('user-secret-info');
if ($user->authenticated == true) {
if ($user->expired < time() && $user->reason == self::NOT_LOGGED_IN) {
// Logout user due inactivity
$user->authenticated = false;
$user->reason = self::INACTIVITY;
} else {
// Slide
$user->expireTime = time() + $user->expireDelta;
}
}
// Dont forget to save session
$this->sesssion->set('user-secret-info', $user);
}