I’m trying to insert logged out users details in a tracking table(username, ipaddress, logout time, etc..). If a user logs out in a correct way by clicking the logout button, then I can write an insert query in a “logout.php” page. If a user closes the browser then I can call the onunload() function, and make AJAX call do insert the query.
Now my question is, if the session is destoryed by some other means like power shutdown, how do I log this event. Is there any other Event Handling function to do this beside using a CRON?
What you’re essentially asking is how do you know if someone has disconnected without properly logging off. The only way of knowing this is using a timeout. The question of how to run code on timeout is answered here: PHP session timeout callback?.
So yeah, you need to write CRON or some other Event Handling function here.