close button in browser

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tisa
Forum Commoner
Posts: 27
Joined: Fri Nov 28, 2003 1:14 am

close button in browser

Post 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:
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post 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
tisa
Forum Commoner
Posts: 27
Joined: Fri Nov 28, 2003 1:14 am

i am using session

Post 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.
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post 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().
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
tisa
Forum Commoner
Posts: 27
Joined: Fri Nov 28, 2003 1:14 am

close button

Post by tisa »

if i set session.cookie_lifetime to "1", what will it happen. becuase i havn't use this function before.
tisa
Forum Commoner
Posts: 27
Joined: Fri Nov 28, 2003 1:14 am

other method

Post by tisa »

so does it has another method to empty all sessions if user click the close button?
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post 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?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post 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
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Re: other method

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