I came across a problem: to logout a user automagically when the session is expired. I am trying to mimic the behavior in SugarCRM where once your session is expired, an alert tells you you've been logged out and you are redirecrec to the login screen to re-login. This happens with or without user interaction.
So far, in yii2, the user has to perform a request beforehand. The session may have expired but the page is maintained until the user tries to perform a new request. While processing this request, the application can then check using controller filters, or a beforeAction()
hook.
I would like to redirect them to the login page as soon as their session expires. How do I do this automagically?
All of the answers above are valid except... you have to implement the session in another way.
Any call to the server will basically reset your normal session. By checking every x seconds that you are still logged in you will make it so you are never logged out. On every check call your session expiry time will reset.
So this has to be combined with the fact that you will modify how the session is handled. You want on an actual page navigation to reset the session timer, not like PHP handles it by default.