Jump to content

If a user closes his browser, all sessions will be destroyed ?


jd2007

Recommended Posts

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.