You cannot do it alone with PHP, but rather you have to combine php with JavaScript.
Conceptual model can be simple.
When somebody closes a window it triggers JavaScript interpreter to execute a function which might have a code like
function trigger_php()
{
window.location="http://www.mysite.com/php_script.php?m=1";
}
php_script.php could be the same page as the user has at the moment, meaning that no change will take place.
It is just an idea, but you can work with it to see what's the best way to do it. If it is too complicated, then think -> chances are you'll come up with a better solution - it always works like that!
Di