When ever user leaves chat page (Either by logging out or just by simple closing the browser window). Chat script instantly detects that user left and show offline sign. This process takes place in few seconds how this really works?
I am an ASP.NET/c# developer apart from it I use JavaScripts and rarely PHP. Please don’t exceed answer(s) to other languages.
Just have your JavaScript chat code send a message to the server every 2 seconds using XMLHttpRequest. When you don’t receive a message, that means that the user has closed the window.