Page 1 of 1

close button in browser

Posted: Thu Feb 12, 2004 2:57 am
by tisa
i want use the function to detect the close button in browser. If user click the close button without logout, i want to foce the user to logout.

Someone can help me :roll:

Posted: Thu Feb 12, 2004 3:00 am
by greenhorn666
Why would you want to do this?
Besides this is not PHP code, but client side JavaScript...
If you want to force the user to logout, you might rely on the cookie specs:
[php_man]setcookie[/php_man]
bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])
<!-- snip -->
expire: If not set, the cookie will expire at the end of the session (when the browser closes).
<!-- snip -->
But, as you will reply, I know: WHEN THE BROWSER CLOSES, not the window :P

i am using session

Posted: Thu Feb 12, 2004 3:07 am
by tisa
sorry, i am using session to store data.
can you tell me how to empty the session if the window close.

because i use session to check the idle time, so i have to empty the session immediately after user close the window.

Posted: Thu Feb 12, 2004 3:10 am
by greenhorn666
Well Yes, but how do you link the session back to the browser?
Cookie most probably or URL rewrite?
In the second case, you loose the session as soon as you close the window (and I mean window!)
In the first case use the [php_man]session[/php_man]
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().

Posted: Thu Feb 12, 2004 3:20 am
by JayBird
greenhorn666 wrote:Well Yes, but how do you link the session back to the browser?
Cookie most probably or URL rewrite?
In the second case, you loose the session as soon as you close the window (and I mean window!)
In the first case use the [php_man]session[/php_man]
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().
This doesn't work on some browsers/OSes.

I developed an intranet for a company, an poeple were logged out when they closed their browser apart from when they were on a MAC using IE 5.

Mark

close button

Posted: Thu Feb 12, 2004 3:21 am
by tisa
if i set session.cookie_lifetime to "1", what will it happen. becuase i havn't use this function before.

other method

Posted: Thu Feb 12, 2004 3:22 am
by tisa
so does it has another method to empty all sessions if user click the close button?

Posted: Thu Feb 12, 2004 3:24 am
by greenhorn666
Bech100 wrote: This doesn't work on some browsers/OSes.

I developed an intranet for a company, an poeple were logged out when they closed their browser apart from when they were on a MAC using IE 5.
You mean IE on Mac doesn't follow the Netscape cookies specs or it keeps a process running that never ends, hence the persistence?

Posted: Thu Feb 12, 2004 3:25 am
by JayBird
do a search on this site, i had the same issue a while back and it was discussed in detail with solutions.

There IS NOT an easy way to detect when the browser closes.

Mark

Posted: Thu Feb 12, 2004 3:31 am
by greenhorn666
Bech100 wrote: There IS NOT an easy way to detect when the browser closes.
Hence my reaction to rely on the cookie specs

Re: other method

Posted: Thu Feb 12, 2004 3:36 am
by greenhorn666
tisa wrote:so does it has another method to empty all sessions if user click the close button?
So the answer is, and for everyone
Do not use a cookie to store the session, but rely on url rewrites!

Which is anyway safer, since you can force the user to have cookies enabled.