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

nizam0786's avatar

When session expires logout but alert the user before doing so

HI Guys,

I want to redirect the user to the login page after the session expires rather than only noticing after refreshing the page.

Also when the session has 60 seconds left I want a pop up to appear with a warning message 'Your session is due to expire in 1 minute due to inactivity' and only on click does the session remain and user is not logged out.

any ideas how I should go about doing this. I have set the session timeout in the env file and have looked into the handler method but just feel they maybe an easy way of doing this.

thanks in advance.

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

This can only be done from the client javascript - and then the client does not truly know when the session will expire.

The client in one browser window can believe the session is about to expire when the user is working quite happily in another tab

I built a little website to demonstrate a few related items, one of which handling the session expiring on a form.

See https://uxp.novate.co.uk/

There is also a link to the code on Github.

1 like

Please or to participate in this conversation.