Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: on close

  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    on close

    In php is there a method for that can be used when a user closes the browser?
    I want to set a variable when the user closes the window

    Thanks

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    PHP does not interact with the browser except through the HTTP request area. Javascript has an onclose() function, which isn't reliable as the browser can choose to ignore it (most popup blockers block this event).

  • #3
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    No. PHP runs on the server, not the client. Your variable has no meaning by the time the client is using the page (unless it's session or application scope).

    Javascript can catch the page being unloaded, but that's about it. And even that is iffy with tabbed browsers since you don't know if the entire browser is closed or just a tab.
    Web applications are best coded with the stateless nature of http in mind. Do your cleanup on session timeout, if you can, or code cleanup periodically in a stateless manner.
    Amazon has some great examples of how they handle things like stuff left in the shopping cart and whatnot.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #4
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for that!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •