Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php how to execute function on session timeout

I have $_SESSION variables containing user login username that have the default session life set ( 24 minutes I think ). I'm wondering if there is a way to execute a function on session timeout.

I know I can tell the page to execute the function when the user reloads the page and the session variable has expired but I'm trying to figure out a way for the server to do this by itself. Is there such a method?

My Reasoning: When the user logs in I report to my database and update the user record for 'lastlogin'. I want to update 'lastlogout' when the user clicks logout or when the $_SESSION variable expires.

like image 367
sadmicrowave Avatar asked Oct 11 '22 16:10

sadmicrowave


1 Answers

Try settings callbacks in session_set_save_handler on close and gc (garbage collector).

like image 124
Exos Avatar answered Oct 14 '22 08:10

Exos