jd2007 Posted August 12, 2007 Share Posted August 12, 2007 how can i check wheter a user closed his browser ? Quote Link to comment https://forums.phpfreaks.com/topic/64515-if-a-user-closes-his-browser-all-sessions-will-be-destroyed/ Share on other sites More sharing options...
hitman6003 Posted August 12, 2007 Share Posted August 12, 2007 When the browser is closed, the cookie that is used for the session is automatically destroyed by the browser. The session data isn't removed by the server until the timeout expires, but because the cookie is destroyed by the user's browser, they are no longer associated with that session. Quote Link to comment https://forums.phpfreaks.com/topic/64515-if-a-user-closes-his-browser-all-sessions-will-be-destroyed/#findComment-321615 Share on other sites More sharing options...
NArc0t1c Posted August 12, 2007 Share Posted August 12, 2007 A cookie is not destroyed by the browser when the user closes the window(by default). A session is destroyed, the server still holds the session(default for 15 minutes) until it expires. A way you could detect if a user closes the browser, navigates away, is to implement a cookie at the same time as the time the session was created, and with an simple if statement, check if the session is there, if not, check for the cookie and alert the user they navigated away from the page. HTML can also detect this, with a function called onunload that's implemented within the body tag. But not much software can actually really detect if the user "closes" the browser window. Here is an example script to check if the user moves away, if so then alert them a goodbye message. <html> <head> <script type="text/javascript"> function goodbye_message() { alert("Good Bye"); } </script> </head> <body onunload="goodbye_message()"> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/64515-if-a-user-closes-his-browser-all-sessions-will-be-destroyed/#findComment-321630 Share on other sites More sharing options...
hitman6003 Posted August 12, 2007 Share Posted August 12, 2007 PHP's session cookies are destroyed with the user closes the browser. It can be done with any cookie by setting the lifetime to 0. session.cookie_lifetime integer session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0. See also session_get_cookie_params() and session_set_cookie_params(). Note: The expiration timestamp is set relative to the server time, which is not necessarily the same as the time in the client's browser. http://us3.php.net/manual/en/ref.session.php#ini.session.cookie-lifetime Quote Link to comment https://forums.phpfreaks.com/topic/64515-if-a-user-closes-his-browser-all-sessions-will-be-destroyed/#findComment-321638 Share on other sites More sharing options...
NArc0t1c Posted August 12, 2007 Share Posted August 12, 2007 The cookie is not destroyed automatically. There is no communication between the server and the client after the browser is closed. The cookie on the server, that is destroyed, but not the clients. And don't trough the manual at me, that is actually a session, not a cookie. Read the manual. Edit: Spelling.. Quote Link to comment https://forums.phpfreaks.com/topic/64515-if-a-user-closes-his-browser-all-sessions-will-be-destroyed/#findComment-321643 Share on other sites More sharing options...
hitman6003 Posted August 12, 2007 Share Posted August 12, 2007 I don't think you understand...when the expire time for the cookie is set to 0, the browser will destroy it when closed. This is true for ANY cookie, not just the one set by the session handler. I will THROW the manual at you until you understand that the default behavior is to set the expire to 0 so that the session cookie is destroyed when the user closes their browser. Quote Link to comment https://forums.phpfreaks.com/topic/64515-if-a-user-closes-his-browser-all-sessions-will-be-destroyed/#findComment-321647 Share on other sites More sharing options...
NArc0t1c Posted August 12, 2007 Share Posted August 12, 2007 I don't want to start a argument, I think I misunderstood you, or the other way around. I thought you meant/said that the cookie is destroyed when the browser windows is closed, even when the expire time is more than zero. Quote Link to comment https://forums.phpfreaks.com/topic/64515-if-a-user-closes-his-browser-all-sessions-will-be-destroyed/#findComment-321657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.