I am building a chat room and I have to determine whether a user is online or not. So when a user logs in, I update his status as online and when he logs out, I update his status as offline, but when the user simply closes the browser, the status remains online.
To fix this I need to execute a server side code on the event of browser termination. How do I do this?