Immediately I say that any beforeunload and onbeforeunload from Javascript are not suitable.

  • one
    But PHP does not know anything about closing the site, so it will somehow have to do it through JS. - SmInc
  • one
    beforeunload is the only possible way, others are not - andreymal
  • 2
    Please do not do this. I don’t want to return to such sites - axmed2004 pm
  • one
    @ axmed2004 that's for sure. I do not go to such sites a second time. - KAGG Design

2 answers 2

No, closing the browser is just closing the application, such an action. No requests to the server will be sent. Accordingly, your PHP daemon will not know about it. You can end up using JS , for example, via WebSocket , catch the event of closing a tab on the browser, and send it to the server.

But in general, of course, this is not desirable. You are not going to make banners from the 2000s?

    php - works on the server, and the browser window, as you know, is the client part. See how to emit button close behavior on JS