I know this belongs to another forum, but I think I shall get more answers here :

How do I ensure that if the client closes a browser window, it will somehow manage to trigger something at the server side so I can end the session?

.