954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to Update database when the Browser is closed

Hi
I have updated the database when browser is closed,But i have a small problem.i.e. The database is updating when the page is refreshing also.
I need that the Database should be updated on when the browser is closed(Not updated when page is refreshed).

Naveenk2k
Newbie Poster
1 post since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

"The onLoad and onUnload events are triggered when the user enters or leaves the page." -- w3schools

A refresh is leaving a page and then entering the same once again. I don't think there is a way to see if the same page will be loading again, or if the browser is closing.

onbeforeunload only appears to be working in IE en FF.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

If a browser reloads a new HTTP request is sent. So what you can do is wait a few seconds for the next HTTP Request.

eg:

On the PHP page that updates the DB do a

sleep(15);

This way the script waits for 15 secs. Then check if the user session has been updated after the script went to sleep. If so, then a new request was made.

You could probably take that down to 10 or even 5 secs.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: