473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

UPDATE on close

zorgi
431 Expert 256MB
Hello people

I have a situation where i need to update database on user closing browser window. What would be the best way of approaching / solving this problem.

Thank you
Nov 7 '08 #1
7 2251
nathj
938 Expert 512MB
That's a tricky issue. As far as I am aware there is no way to reliably detect a browser close. You see browser activity is detected client-side and your update is done server side.

If the user closes the browser there is no client-side and so you have no way of detecting any thing as there is no client side to run scripts to tell your server side scripts to perform an update.

In a nutshell what you have asked can't be done.

So, what is the point of this update on quit idea? There is, as my old mum says, more than one way to kill a pig/skin a cat. Let us know what the point of this is and we may be able to offer an alternative idea for you to explore.

Cheers
nathj
Nov 7 '08 #2
zorgi
431 Expert 256MB
That's a tricky issue. As far as I am aware there is no way to reliably detect a browser close. You see browser activity is detected client-side and your update is done server side.

If the user closes the browser there is no client-side and so you have no way of detecting any thing as there is no client side to run scripts to tell your server side scripts to perform an update.

In a nutshell what you have asked can't be done.

So, what is the point of this update on quit idea? There is, as my old mum says, more than one way to kill a pig/skin a cat. Let us know what the point of this is and we may be able to offer an alternative idea for you to explore.

Cheers
nathj

First of all thanx nathj.

The problem:
I have a page that can only be viewed by one account/user of the group. There is unlimited number of groups but within a group only one user can see the page at the time. I was going to record user details into database when he logs in and basically stop anyone from his group to log in at the same time. However if he doesn't log off but instead closes the window,...well I have a problem, because database has not been updated. I think I have to skin this cat with user activity checks and/or time limits, of course that's unless someone comes forward with elegant solution.
Nov 7 '08 #3
nathj
938 Expert 512MB
I see, this cat is wriggling around and refusing to be skinned. Well, before I stretch the analogy, or the cat, to far I'll press on with what may be a workable idea.

I should say before outline this that it probably has more holes than a tea strainer.

Here's my idea:

1. User 1 attempts access the restricted page and you check in the DB and see that he can, so you store this fact and some indicator the session or cookie.

2. User 1 shuts the browser and goes to find a cat or make a cup of tea or something. most importantly he does not log out

3. User 2 attempts to access the restricted page so the PHP check sees that there is some sort of cookie/session ID listed and so attempts to reach that session to see if it's active. If it is active the page is locked if it's not active then the DB is updated to reflect user 1 disappearing and user 2 appearing.

Does that make sense? Now, how to achieve all that? Also, there are potential issues with session timeouts and stuff, but I still think it is worth pursuing a bit further.

I hope that helps a bit more, and I promise to stay away from cats everywhere.

Cheers
nathj
Nov 7 '08 #4
zorgi
431 Expert 256MB
I'll your this apptoach, will see where it takes me and rusalt will post here.
Nov 7 '08 #5
You may try the "onload" attribute of the html body tag to trigger an AJAX event or you can use cron jobs ( in your problem might not help much ).
Nov 7 '08 #6
Atli
5,058 Expert 4TB
Hi.

You could try using JavaScript timers and AJAX to keep track of the user while he browses you pages.

That is; you could set up a database that keeps track of which user is logged in that has a very very short time-out period, after which the user is considered inactive and logged out.
That timeout could be something like 30 seconds.

On the page, you could have a JavaScript timer event that sends an AJAX request to a "refresh" page, that would update the database in order to keep the user "active". You could call it like every 15 seconds just to make sure that the user doesn't get "lagged" out.

This way, if the user closes his browser, the AJAX won't fire, the database won't be refreshed and the user would time-out and become inactive, allowing other users to log in instead.
Nov 8 '08 #7
zorgi
431 Expert 256MB
Thank you all for your input. This is what I did.

First I tried nathjs approach with sessions. However what I wrote was messy so before finishing it I switched to AJAX approach.

Basically this is my body tag for the page:

[HTML]
<body onbeforeunload="ajax_start(); alert('Click OK to log off ');">
[/HTML]

ajax_start() is my function that starts ajax that calls PHP script that updates the database (logs user off).

alert('Click OK to log off '); is not here just to look good but to give ajax enough time to update the database. Without it database doesn't get updated.
Nov 11 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: René Kabis | last post by:
People, I am at my wit's end. I am using the exact code from http://aspnet.4guysfromrolla.com/articles/071002-1.aspx And yet, the code does not manage to update the database. When I go to...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
9
by: zMisc | last post by:
When I try to update record, I kept getting this error: Row cannot be located for updating. Some values may have been changed since it was last read. No other users are accessing the database...
1
by: Mark Reed | last post by:
Hi All, I'm having a problem with the following code. I've read quite a lot of old posts regarding the issue but none seem to affer a solution. The scenario is. I have a bound form which...
2
by: technocrat | last post by:
HOW CAN THIS BE DONE IN JAVA??? THIS IS POSITIONED UPDATE EXEC SQL DECLARE C1 CURSOR FOR SELECT * FROM EMPLOYEE FOR UPDATE OF JOB; EXEC SQL OPEN C1;
2
by: lmnorms1 | last post by:
Hello, I am looking to update a record that was read in with OleDbDataReader. I have the record in reader but now with the reader connection open; how do I update it. Any advice would be...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
2
by: Presto | last post by:
I am making a front end mdb so users can enter new members data. I can then import this into the master database on the backend and erase the existing info on the front end to keep the data...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.