You will need to use javascript. Php cannot tell what is going on with the browser. Javascript does communicate with the browser though.
<body onunload="jsfunction()"> then on your jsfunction() use ajax to send the info to the server side and alert you if the window is closed