0

I have a large application which expires the session data after 30 minutes of idle time. Now I want to call a function before the session expiration.

My Reason for above question: I am storing a unique id in database for some purpose. When the user clicks logout, I will delete that ID. I want to delete that ID even when the user session expires after idle time.

kowshiga
  • 11
  • 1
  • 4
  • If I were you I will use a client side JS to regularly check the idle time (say once per minute) and then at 30-minute I will call a separate PHP by ajax to do the job . (of course you need to reset this JS to time=0 whenever there is user activity) – Ken Lee Feb 11 '22 at 12:21

1 Answers1

0

As far as i know , it will be bad practice to set a "counter" for users to check if their session is expired.

If you need this ID to see who is connected in your administration aria , one possible way to do it is by checking the session expiration on loading admin page , and then delete the expired sessions rows then showing only active sessions.

So my idea is that while you are not using your admin dashboard it is okay that some sessions ID's still in your database , once you try to see who is online , the check function is called and clean up your data for expired session.

THAT IF YOU ARE USING THAT ID FOR SOMTHING LIKE THAT SINCE YOU DIDN''T SHARE THE WHOLE REASON OF WHY YOU NEED TO DO SO.

  • 1
    My reason is I am communicating with another white label site and getting a return callback from that site ... I will get the same id in my callback request, if my db id and the id i am getting from request matches then the process continues . else I will Not do anything in that function. This case works well for me as far as the user logs out manually but If the user's session expires due to idle timeout, The id in the database still exists which suppose to be not there – kowshiga Feb 11 '22 at 12:32