PHP is not going to know that the browser closed. You could send something via JavaScript's onunload
or onbeforeunload
(making sure it includes the current session cookie) to tell PHP to clear the data, though I don't know how reliable that is, plus apparently some other things besides closing the tab/browser could trigger it, too. Or, you could maybe just configure your PHP sessions to have a sufficiently short lifetime that they expire after whatever amount of time seems right for your needs (hopefully not so short that you p**s off users by expiring it while they're still trying to use it).