why would you need that? if he is gone, he is gone 🙂))) okay, i think you should look at connection abort:
http://www.php.net/manual/en/function.connection-aborted.php
before using that, make sure your script wont end when a user disconnect... so you will be able to catch it.
http://www.php.net/manual/en/function.ignore-user-abort.php
i am not sure how would you catch someone who closes the browser when the script has already finished executing? i dont think its possible... you will have to periodicaly check sessions... if it is older than X minutes, mark it as finished. any better ideas?
Matjaz