Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

execute code when browser closes?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Re: execute code when browser closes?

Postby WiZARD » Wed Jul 10, 2002 10:57 pm

converge wrote:I am designing a site where paying users can login to a searchable scientific database. But I only want them to be able to be logged in on one computer at a time. If a user clicks the logout button, I set a field in my table to LoggedIn = False. But what if they just close the browser? Then the database still thinks they're logged in. Is there a way for sessions to accomplish this task?


Hi!
You can use session on your site or cookie. You can config session/cookie that them destroy than browser close.
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby Oleg Butuzov » Thu Jul 11, 2002 1:14 am

or you can open new window when work complete!

this window will start you script.
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby elitecodex » Thu Jul 11, 2002 4:40 am

Im not sure if there is a "session_onend" function that is over-ridable. However, while overlooking the PHP documentation, I came across this function session_set_save_handler()... This might help you out.

Let me know if this helps

Will
elitecodex
New php-forum User
New php-forum User
 
Posts: 68
Joined: Tue Jul 09, 2002 8:45 am
Location: East Coast, USA

Postby Jay » Fri Aug 02, 2002 11:43 am

When a browser is closed it doesn't send any information back to the website (at least not that I'm aware of). In between serving pages the server doesn't know if the browser still exists or not. The session is managed by use of a cookie (the session manages it automatically) which is set to expire immediately, so as long as your browser window doesn't close the cookie value (and therefore session ID) will remain active.

If you wanted to log a user out you could put an Javascript onUnload command in the body tag to open up a new window (Goodbye page, or 'Logging you Out' which would contain the code to log a user out), and this will be executed when a user leaves the page.

Of course you don't want this to happen every time they change a page, so you might want to make some use of frames and put the code within the frameset, so when they leave the site or close the browser it'll activate the code.

I've never actually tried it myself, but in theory it should work. You might have to play around a bit with it first.
Jay
 

Postby iLLuZZiOn » Mon Aug 05, 2002 2:41 am

One option i can think of is making a popup window that pops up then the main page is accessed or when the user logs in. and if u can start with the window maximised.

This window could have the close button disabled, and at the top and bottom of the page it has a close button, when clicked it logs the user out then closes the window


window.onClose and window.onExit don't work in IE 6 :(
iLLuZZiOn
New php-forum User
New php-forum User
 
Posts: 9
Joined: Fri Aug 02, 2002 5:59 pm

Postby Jay » Mon Aug 05, 2002 4:50 am

iLLuZZiOn wrote:window.onClose and window.onExit don't work in IE 6 :(

Did you try onUnload in the body tag?
Jay
 

Postby iLLuZZiOn » Thu Aug 15, 2002 7:58 pm

Did you try onUnload in the body tag?


but evertime the user clicks on a link or refreshes the page it will log them out...

unless at the beggining of everypage there is a script that logs them back in automatcly?
iLLuZZiOn
New php-forum User
New php-forum User
 
Posts: 9
Joined: Fri Aug 02, 2002 5:59 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron