Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lako's avatar
Level 2

Monitor whether session is expired in L5.1

Hi guys I need to know the point session is expired. I've set session life time in config/session.php like below.

'lifetime' => 1,

And then I need to implement redirecting the page to the login first page when the session is expired. How can I implement this? Thank you for your any kind of help.

0 likes
4 replies
Snapey's avatar
Snapey
Best Answer
Level 122

You can't redirect the client from the server, and you cannot monitor the session timeout from the server since everything is request driven.

One approach is to set a timer on each page in javascript and if it passes the session length then it redirects itself.

If you have ajax calls on the page then you will need to take this into account, and restart the timer each time an ajax event occurs.

1 like

Please or to participate in this conversation.