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

yadeyinka's avatar

session time out

how do I make automatic logout once session timed out? thanks

0 likes
4 replies
Snapey's avatar

You would need to have a timer in the client that told the user that the session has timed out. There is nothing happening in the server that you can use to determine the session has expired.

This is flawed however since the user could have two windows open. One could happily be used whilst the other would be showing that the session was expired.

Suppose the session expiry is the default 120 minutes.

At each page load, start a javascript timer in the client. If 120 minutes passes, the session might have expired. Send a small ajax request to the server and if it replies with a session expired message, show a modal that advises the session has expired. Otherwise, wait a further 120 minutes and try again.

If you keep asking the server if the session is alive then it will always be alive.

Snapey's avatar

Sorry, no. Its not a very common request.

Please or to participate in this conversation.