Actually, a session isn't destroyed by the client closing their browser (closing their browser, all windows of their browser, will remove the session cookie though), it is destroyed either explicitly (session_destroy()) or by timing out. You cannot detect, except by the server timing a session out, that a user has closed the browser. However, if you use your method, and the user sits and "lurks" for five minutes, the server will think they have left.