Ask a Question related to PHP Development, Design and Development.
-
Ben Paley #1
Detecting when a user leaves a page
Hello,
I need (I think) to find a way of detecting when a user leaves a web-page;
by hitting a link or the Back button, by typing into the address window, or
by closing the browser.
Here's why:
I'm writing a system to give a number of users access to documents (stored
in a mysql database) for shared editing. Most aspects of this have been
pretty easy, but I'm having trouble with the check-out part of it.
So far: when a user opens the edit page (doc_id sent in the query string)
the document is flagged as open in the database and subsequent attempts to
open it are refused. When the user hits Save, the document is updated and
the flag reset so the document can be opened. There's a time-out so that
after a couple of hours or the document is flagged as closed
irrespectively, on the assumption that they must have given up or got
bored.
The problem is that users may not hit the Save button! At the moment any
movement away from the page except via save means, effectively, that the
document is locked until the end of the time-out - even from the user who
opened it, so that, for instance, hitting Refresh is like letting your door
slam behind you when your key are inside...
This last, I can cure with a session variable holding the doc-id so that the
original user will retain access to the document even if they wander away
in the meantime - or maybe by putting the user's username into another
database column.
That's OK for /them/, but if they just leave the page or close their browser
without hitting Save, and without intending to come back, I can't think of
any way to detect this and reset the flag so that other users will again
have access to the document!
I'm tearing my hair out here: all suggestions very welcome.
Thanks in advance,
Ben
Ben Paley Guest
-
Detecting user country
I am creating a page for a shop and there is a UK shop and an International shop. I have created both pages, each page has a link to the other as... -
Can I perform a function when user leaves site?
I need to update a database record when a User closed his browswer or leaves the site. Is this possible? If so, how would I do that? -
Capturing event when user leaves a cell?
Does anyone know what event this might be? In a datagrid, user clicks on Edit on a row, types data in the first cell, then goes to the next cell. ... -
#24858 [Opn->Bgs]: proc_open() leaves zombie processes if user cancels page load
ID: 24858 User updated by: jr-php2 at quo dot to Reported By: jr-php2 at quo dot to -Status: Open +Status: ... -
#24858 [NEW]: proc_open() leaves zombie processes if user cancels page load
From: jr-php2 at quo dot to Operating system: Red Hat Linux 9.0, kernel 2.4.21 PHP version: 4.3.2 PHP Bug Type: Program... -
Good Man #2
Re: Detecting when a user leaves a page
Ben Paley <ben@spooty.net> wrote in
news:XMI2d.1478$c56.398@newsfe5-gui.ntli.net:
You won't be able to detect when a user leaves a page, so give up even> That's OK for /them/, but if they just leave the page or close their
> browser without hitting Save, and without intending to come back, I
> can't think of any way to detect this and reset the flag so that other
> users will again have access to the document!
>
> I'm tearing my hair out here: all suggestions very welcome.
considering that as an option. You can set a time limit for documents,
however....
In your documents table, when a file is checked out, record the timestamp.
When another user wishes open that file, a script can see if the database
reports the file as checked back in (and therefore give access immediately)
or if the document is reported as 'out', the script would compare the
timestamp of the request to the timestamp in the database... if 10 minutes
(or whatever you choose) has elapsed, let the new user sign out the
document...
It's pretty similar to your timeout scheme, but there really aren't a whole
lot of options as far as I know...
Good Man Guest
-
J.O. Aho #3
Re: Detecting when a user leaves a page
Ben Paley wrote:
Hitting a link is quite easy, just make the links to point at a php page on> Hello,
>
> I need (I think) to find a way of detecting when a user leaves a web-page;
> by hitting a link or the Back button, by typing into the address window, or
> by closing the browser.
your own site which takes the remote source as the argument, then the page
does what you want it to do before the user leaves your site and then redirect
the user to the external page.
The rest of the methodes will go quite unnoticed by you.
You can use a cookie fo the user who opened the edit, set the lifetime for the> The problem is that users may not hit the Save button! At the moment any
> movement away from the page except via save means, effectively, that the
> document is locked until the end of the time-out - even from the user who
> opened it, so that, for instance, hitting Refresh is like letting your door
> slam behind you when your key are inside...
cookie to the same length as the timeout time, then you can make a check for
the cookie to see if the user is the one who opened the and allow that one to
edit as long the text is locked (when it's saved the cookie is removed).
//Aho
J.O. Aho Guest
-
Ben Paley #4
Re: Detecting when a user leaves a page
Good Man wrote:
This is exactly what I did, in fact - I didn't go into details because I> Ben Paley <ben@spooty.net> wrote in
> news:XMI2d.1478$c56.398@newsfe5-gui.ntli.net:
>>>> That's OK for /them/, but if they just leave the page or close their
>> browser without hitting Save, and without intending to come back, I
>> can't think of any way to detect this and reset the flag so that other
>> users will again have access to the document!
>>
>> I'm tearing my hair out here: all suggestions very welcome.
> You won't be able to detect when a user leaves a page, so give up even
> considering that as an option. You can set a time limit for documents,
> however....
>
> In your documents table, when a file is checked out, record the timestamp.
> When another user wishes open that file, a script can see if the database
> reports the file as checked back in (and therefore give access
> immediately) or if the document is reported as 'out', the script would
> compare the timestamp of the request to the timestamp in the database...
> if 10 minutes (or whatever you choose) has elapsed, let the new user sign
> out the document...
hoped it wasn't relevant!
This is problematic, though: set the time limit too low and other people
will be able to open the document before an earlier user has finished. Set
it too high and people are locked out for ages... the point of balance will
be when I get both problems equally, I fear, rather than neither.
What do you think about using a javascript onUnload() to call a php script?
I can think of any number of objections to this, but is it even
theoretically do-able? Perhaps I should just start playing (but I smell a
dead-end...)
Well, thanks a lot for your help even if it's more negative than positive -
perhaps you have just saved me hours or days of fruitless key-bashing.
Cheers,
Ben
Ben Paley Guest
-
Ben Paley #5
Re: Detecting when a user leaves a page
J.O. Aho wrote:
Thanks a lot for your help. It begins to look as though my central problem> Ben Paley wrote:>>> Hello,
>>
>> I need (I think) to find a way of detecting when a user leaves a
>> web-page; by hitting a link or the Back button, by typing into the
>> address window, or by closing the browser.
> Hitting a link is quite easy, just make the links to point at a php page
> on your own site which takes the remote source as the argument, then the
> page does what you want it to do before the user leaves your site and then
> redirect the user to the external page.
>
> The rest of the methodes will go quite unnoticed by you.
>
>>>> The problem is that users may not hit the Save button! At the moment any
>> movement away from the page except via save means, effectively, that the
>> document is locked until the end of the time-out - even from the user who
>> opened it, so that, for instance, hitting Refresh is like letting your
>> door slam behind you when your key are inside...
> You can use a cookie fo the user who opened the edit, set the lifetime for
> the cookie to the same length as the timeout time, then you can make a
> check for the cookie to see if the user is the one who opened the and
> allow that one to edit as long the text is locked (when it's saved the
> cookie is removed).
is simply not sortable, so I'll have to kludge round it.
BTW, some googling seemed to show that this would be quite easy in asp,
where there's an event handler for a session finishing!
Cheers,
Ben
Ben Paley Guest
-
Rupe #6
Re: Detecting when a user leaves a page
"Ben Paley" <ben@spooty.net> wrote in message
news:XMI2d.1478$c56.398@newsfe5-gui.ntli.net...or> Hello,
>
> I need (I think) to find a way of detecting when a user leaves a web-page;
> by hitting a link or the Back button, by typing into the address window,door> by closing the browser.
>
> Here's why:
>
> I'm writing a system to give a number of users access to documents (stored
> in a mysql database) for shared editing. Most aspects of this have been
> pretty easy, but I'm having trouble with the check-out part of it.
>
> So far: when a user opens the edit page (doc_id sent in the query string)
> the document is flagged as open in the database and subsequent attempts to
> open it are refused. When the user hits Save, the document is updated and
> the flag reset so the document can be opened. There's a time-out so that
> after a couple of hours or the document is flagged as closed
> irrespectively, on the assumption that they must have given up or got
> bored.
>
> The problem is that users may not hit the Save button! At the moment any
> movement away from the page except via save means, effectively, that the
> document is locked until the end of the time-out - even from the user who
> opened it, so that, for instance, hitting Refresh is like letting yourthe> slam behind you when your key are inside...
>
> This last, I can cure with a session variable holding the doc-id so thatbrowser> original user will retain access to the document even if they wander away
> in the meantime - or maybe by putting the user's username into another
> database column.
>
> That's OK for /them/, but if they just leave the page or close theirThis is off the top of my head...> without hitting Save, and without intending to come back, I can't think of
> any way to detect this and reset the flag so that other users will again
> have access to the document!
>
> I'm tearing my hair out here: all suggestions very welcome.
>
> Thanks in advance,
> Ben
Lock the record at the database level.
I think it is possible to set a time out on a locked record/table.
Unlock after update.
If they move away from the page their connection to the db is closed and
locks are reset ie. unlocked.
Plus you don't have to bother with the flag.
Not sure how you'd let other users know the record was locked...
HTH
RUPE
Rupe Guest
-
Ben Paley #7
Re: Detecting when a user leaves a page
Ben Paley wrote:
Or how about this:> Hello,
>
> I need (I think) to find a way of detecting when a user leaves a web-page;
> by hitting a link or the Back button, by typing into the address window,
> or by closing the browser.
Is there any way to determine whether a given session id (not necessarily
the current session) is valid? If so, we could store the opening user's
session id in the database, then check to see (in effect) if their browser
is still open when someone else finds the document flagged open.
The documentation look unpromising on this point, but I thought it might be
worth asking.
Cheers,
Ben
Ben Paley Guest
-
Zurab Davitiani #8
Re: Detecting when a user leaves a page
Ben Paley wrote:
The problem starts from the point where HTTP is not a session based> Thanks a lot for your help. It begins to look as though my central problem
> is simply not sortable, so I'll have to kludge round it.
protocol. What you are trying to do is replicate a true session and there
are obvious limitations. You should try the suggestions (including some of
yours) since there is no way to make real sessions with HTTP. Here's a
short summary:
- Javascript onunload event should help, but will not guarantee
- "locking" a document with server timestamp and "freeing" after time
allotted has passed (when not saved)
- presenting the editing user with a Javascript dialog every 10-15 minutes
(or whatever time period) to make sure they are still there
ASP doesn't magically create true sessions over HTTP. It relies on the same> BTW, some googling seemed to show that this would be quite easy in asp,
> where there's an event handler for a session finishing!
methods to track sessions and does not help in your case when:
- scripting is turned off
- browser crashes
- OS crashes
- client disconnects from the internet/network
- etc.
This list would be the same with whatever you can implement in PHP or Perl
or whatever else over HTTP.
Zurab Davitiani Guest
-
Ben Paley #9
Re: Detecting when a user leaves a page
SMJ wrote:
Not bad - but if they'd gone the alert box wouldn't happen, would it?> <alt.php , Ben Paley , [email]ben@spooty.net[/email]>
> <XMI2d.1478$c56.398@newsfe5-gui.ntli.net>
> <Fri, 17 Sep 2004 21:35:51 GMT>
>>>> That's OK for /them/, but if they just leave the page or close their
>> browser without hitting Save, and without intending to come back, I can't
>> think of any way to detect this and reset the flag so that other users
>> will again have access to the document!
>>
>> I'm tearing my hair out here: all suggestions very welcome.
>>
> In theory as i'm only at beginner level .
>
> A timed alert box every 5-10 minutes asking them to save the document -
> if no answer - they have gone .
Ben Paley Guest
-
Ben Paley #10
Re: Detecting when a user leaves a page
Rupe wrote:
This sounds promising. I'll have to go back to the mysql docs and check it> This is off the top of my head...
>
> Lock the record at the database level.
>
> I think it is possible to set a time out on a locked record/table.
>
> Unlock after update.
>
> If they move away from the page their connection to the db is closed and
> locks are reset ie. unlocked.
out.
Well, they wouldn't be able to see the record... hmm... but you're right,>
> Plus you don't have to bother with the flag.
>
> Not sure how you'd let other users know the record was locked...
they'd need to see it to know it was there, and the way things work at the
moment, depending on how the lock works, if they couldn't see it they'd
probably be given a previous version of the document, which would be no
improvement at all!
Well, I'll be poring over the mysql manual tonight.
Thanks very much for your suggestion.
Cheers,
Ben
Ben Paley Guest
-
Zurab Davitiani #11
Re: Detecting when a user leaves a page
Ben Paley wrote:
This doesn't make sense - there is no direct database connection from a>>> If they move away from the page their connection to the db is closed and
>> locks are reset ie. unlocked.
> This sounds promising. I'll have to go back to the mysql docs and check it
> out.
client to the DB server - therefore, when the client moves away from your
page, it doesn't affect any database connection!
Unless you want to implement some client-side distributed COM object ActiveX> Well, I'll be poring over the mysql manual tonight.
control - which, I assume, is not what you mean.
Zurab Davitiani Guest
-
Ben Paley #12
Re: Detecting when a user leaves a page
Zurab Davitiani wrote:
Of course! I sometimes feel like half my time is spent getting around the> The problem starts from the point where HTTP is not a session based
> protocol. What you are trying to do is replicate a true session and there
> are obvious limitations. You should try the suggestions (including some of
> yours) since there is no way to make real sessions with HTTP. Here's a
> short summary:
>
> - Javascript onunload event should help, but will not guarantee
> - "locking" a document with server timestamp and "freeing" after time
> allotted has passed (when not saved)
> - presenting the editing user with a Javascript dialog every 10-15 minutes
> (or whatever time period) to make sure they are still there
>>>> BTW, some googling seemed to show that this would be quite easy in asp,
>> where there's an event handler for a session finishing!
> ASP doesn't magically create true sessions over HTTP. It relies on the
> same methods to track sessions and does not help in your case when:
>
> - scripting is turned off
> - browser crashes
> - OS crashes
> - client disconnects from the internet/network
> - etc.
>
> This list would be the same with whatever you can implement in PHP or Perl
> or whatever else over HTTP.
stateless nature of the web.
Thanks a lot for your systematic presentation of my options so far, I
appreciate your advice.
Cheers,
Ben
Ben Paley Guest
-
Zurab Davitiani #13
Re: Detecting when a user leaves a page
Zurab Davitiani wrote:
Replying to myself here, but I forgot to add that you have an option of> Ben Paley wrote:
>>>>>>> If they move away from the page their connection to the db is closed and
>>> locks are reset ie. unlocked.
>> This sounds promising. I'll have to go back to the mysql docs and check
>> it out.
> This doesn't make sense - there is no direct database connection from a
> client to the DB server - therefore, when the client moves away from your
> page, it doesn't affect any database connection!
>>>> Well, I'll be poring over the mysql manual tonight.
> Unless you want to implement some client-side distributed COM object
> ActiveX control - which, I assume, is not what you mean.
something similar implemented in Java applet where the applet itself makes
connections to the database server - you can have your sessions then. Of
course, be aware of how many simultaneous DB connections you may have.
Zurab Davitiani Guest
-
Ben Paley #14
Re: Detecting when a user leaves a page
Zurab Davitiani wrote:
Oh.> Ben Paley wrote:
>>>>>>> If they move away from the page their connection to the db is closed and
>>> locks are reset ie. unlocked.
>> This sounds promising. I'll have to go back to the mysql docs and check
>> it out.
> This doesn't make sense - there is no direct database connection from a
> client to the DB server - therefore, when the client moves away from your
> page, it doesn't affect any database connection!
Well, that's that, then.
You assume correctly.> Unless you want to implement some client-side distributed COM object
> ActiveX control - which, I assume, is not what you mean.
Thanks again. If anything magically occurs to you, let me know, won't you?
Cheers,
Ben
Ben Paley Guest
-
Ben Paley #15
Re: Detecting when a user leaves a page
Zurab Davitiani wrote:
That sounds like a great idea, if I had any idea how to go about doing it ->>>
>> Unless you want to implement some client-side distributed COM object
>> ActiveX control - which, I assume, is not what you mean.
> Replying to myself here, but I forgot to add that you have an option of
> something similar implemented in Java applet where the applet itself makes
> connections to the database server - you can have your sessions then. Of
> course, be aware of how many simultaneous DB connections you may have.
I guess I probably won't have learnt by the beginning of next week, either.
But I think I'm learning something just from the sort of things you're
thinking of.
Thanks again,
Ben
Ben Paley Guest
-
zeitgeist #16
Re: Detecting when a user leaves a page
Ben Paley wrote:
> Hello,
>
> I need (I think) to find a way of detecting when a user leaves a web-page;
> by hitting a link or the Back button, by typing into the address window,
> or by closing the browser.
>
> Here's why:
>
> I'm writing a system to give a number of users access to documents (stored
> in a mysql database) for shared editing. Most aspects of this have been
> pretty easy, but I'm having trouble with the check-out part of it.
>
> So far: when a user opens the edit page (doc_id sent in the query string)
> the document is flagged as open in the database and subsequent attempts to
> open it are refused. When the user hits Save, the document is updated and
> the flag reset so the document can be opened. There's a time-out so that
> after a couple of hours or the document is flagged as closed
> irrespectively, on the assumption that they must have given up or got
> bored.
>
> The problem is that users may not hit the Save button! At the moment any
> movement away from the page except via save means, effectively, that the
> document is locked until the end of the time-out - even from the user who
> opened it, so that, for instance, hitting Refresh is like letting your
> door slam behind you when your key are inside...
>
> This last, I can cure with a session variable holding the doc-id so that
> the original user will retain access to the document even if they wander
> away in the meantime - or maybe by putting the user's username into
> another database column.
>
> That's OK for /them/, but if they just leave the page or close their
> browser without hitting Save, and without intending to come back, I can't
> think of any way to detect this and reset the flag so that other users
> will again have access to the document!
>
> I'm tearing my hair out here: all suggestions very welcome.
>
> Thanks in advance,
> Ben
The only solution I could think of would involve a little JavaScript. There
is no way for PHP to access the state of the users's browser 'cause it's a
server side language, JavaScript is client side. So a combination would do
the trick.
zeitgeist
zeitgeist Guest
-
Ben Paley #17
Re: Detecting when a user leaves a page
zeitgeist wrote:
> Ben Paley wrote:
>>> Hello,
>>
>> I need (I think) to find a way of detecting when a user leaves a
>> web-page; by hitting a link or the Back button, by typing into the
>> address window, or by closing the browser.I think you're right, unfortunately - good job the target audience is>
> The only solution I could think of would involve a little JavaScript.
> There is no way for PHP to access the state of the users's browser 'cause
> it's a server side language, JavaScript is client side. So a combination
> would do the trick.
unlikely to be using Lynx.
Cheers,
Ben
Ben Paley Guest
-
Al C. #18
Re: Detecting when a user leaves a page
Ben Paley wrote:
You can't detect it. What you need to do is keep a table in your database with>
> That's OK for them, but if they just leave the page or close their browser
> without hitting Save, and without intending to come back, I can't think of
> any way to detect this and reset the flag so that other users will again
> have access to the document!
>
user-1's ID, the doc ID and the time it was requested by user-1. When user-2
comes along and wants the doc, check the table, see if it is in use by anyone
and if so has it been more than X minutes? If so, let user-2 have it and
assume user-1 has left the room. Otherwise, tell user-2 to try again in X
minutes. Of course, you also should put in some logic such that if user-1
goes somewhere else in the application, you clear his entry in the table.
This can get messy when user-1 opens a second window to see another part of
your application and you clear his table entry. Make sure you tell all users
that there is an X-minute limit for using a doc... and not to open multiple
windows. . Finally, make sure you check the table before you do any updates
by user-1 to make sure he still has ownership.
The above is a server-side "solution." There may be a better client-side
solution via Javascript but I don't know much Javascript. We don't use it
because it chokes a lot of browsers.
Al C.
__________________________________________________ ________
Adams-Blake Company, Inc.
***
JAYA123 - the web-based total-office system for the
small biz. Order entry, billing, bookkeeping, etc. for $14.95
a month. Perfect for the small business or start-up.
See demo at: [url]http://www.jaya123.com[/url]
***
Al C. Guest
-
Rupe #19
Re: Detecting when a user leaves a page
"Zurab Davitiani" <agt@mindless.com> wrote in message
news:EpK2d.22316$i%1.18116@newssvr29.news.prodigy. com...and> Ben Paley wrote:
>> >> If they move away from the page their connection to the db is closedit> >> >> locks are reset ie. unlocked.
> > This sounds promising. I'll have to go back to the mysql docs and checkActiveX>> > out.
> This doesn't make sense - there is no direct database connection from a
> client to the DB server - therefore, when the client moves away from your
> page, it doesn't affect any database connection!
>>> > Well, I'll be poring over the mysql manual tonight.
> Unless you want to implement some client-side distributed COM objectOf course that's what I meant!! not really. I did say off the top...> control - which, I assume, is not what you mean.
R
Rupe Guest
-
Rupe #20
Re: Detecting when a user leaves a page
"Ben Paley" <ben@spooty.net> wrote in message
news:XMI2d.1478$c56.398@newsfe5-gui.ntli.net...or> Hello,
>
> I need (I think) to find a way of detecting when a user leaves a web-page;
> by hitting a link or the Back button, by typing into the address window,door> by closing the browser.
>
> Here's why:
>
> I'm writing a system to give a number of users access to documents (stored
> in a mysql database) for shared editing. Most aspects of this have been
> pretty easy, but I'm having trouble with the check-out part of it.
>
> So far: when a user opens the edit page (doc_id sent in the query string)
> the document is flagged as open in the database and subsequent attempts to
> open it are refused. When the user hits Save, the document is updated and
> the flag reset so the document can be opened. There's a time-out so that
> after a couple of hours or the document is flagged as closed
> irrespectively, on the assumption that they must have given up or got
> bored.
>
> The problem is that users may not hit the Save button! At the moment any
> movement away from the page except via save means, effectively, that the
> document is locked until the end of the time-out - even from the user who
> opened it, so that, for instance, hitting Refresh is like letting yourthe> slam behind you when your key are inside...
>
> This last, I can cure with a session variable holding the doc-id so thatbrowser> original user will retain access to the document even if they wander away
> in the meantime - or maybe by putting the user's username into another
> database column.
>
> That's OK for /them/, but if they just leave the page or close theirYour best bet is find it on goooooooooooogle:> without hitting Save, and without intending to come back, I can't think of
> any way to detect this and reset the flag so that other users will again
> have access to the document!
>
> I'm tearing my hair out here: all suggestions very welcome.
>
> Thanks in advance,
> Ben
[url]http://php.resourceindex.com/Complete_Scripts/[/url]
is a start...
Rupe
Rupe Guest



Reply With Quote

