Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > onleave?

Reply
Thread Tools

onleave?

 
 
Thomas Henz
Guest
Posts: n/a
 
      09-07-2003
Hi!

I'm searching for something that lets me write into a mysql db (or just
do sth) when a user leaves a site. that means if the user closes the
browser window. How can I do such a thing? I heard something about a
<body onleave=""> but it doesn't seem to be implemented in browsers or
at least some of them.

Thanks,

Tom

 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      09-07-2003
Thomas Henz wrote:

> I'm searching for something that lets me write into a mysql db (or just
> do sth) when a user leaves a site. that means if the user closes the
> browser window. How can I do such a thing? I heard something about a
> <body onleave=""> but it doesn't seem to be implemented in browsers or
> at least some of them.


You're probably thinking of onunload - but its useless for what you are
planning.

There is no effective way of doing anything on the server in responce to the
user leaving a page.

--
David Dorward http://dorward.me.uk/
 
Reply With Quote
 
 
 
 
Joel Shepherd
Guest
Posts: n/a
 
      09-07-2003
Thomas Henz wrote:
> Hi!


Hi!

> I'm searching for something that lets me write into a mysql db (or
> just do sth) when a user leaves a site. that means if the user
> closes the browser window. How can I do such a thing?


There's no reliable way to do this. HTTP is stateless, so once your
server has filled the user's latest request, you have no way of
knowing if they're viewing it, have closed their browser, have typed
in a new URL and scooted off elsewhere, etc.

About the best you can do is have a session on the server side for
each user that expires after a certain period of inactivity: e.g.,
after 10 minutes with no further requests in that session. When the
session expires, you assume the user has "left the site" and do
something accordingly. Cookies and/or hacked URLs are the usual means
for tracking sessions.

--
Joel.

 
Reply With Quote
 
Thomas Henz
Guest
Posts: n/a
 
      09-07-2003
Joel Shepherd wrote:
> About the best you can do is have a session on the server side for each
> user that expires after a certain period of inactivity: e.g., after 10
> minutes with no further requests in that session. When the session
> expires, you assume the user has "left the site" and do something
> accordingly. Cookies and/or hacked URLs are the usual means for tracking
> sessions.


How can I do that 10 minutes thing without access to mysql files on the
providers side? or is that a php session thing (i smell OT)?

tom

 
Reply With Quote
 
Joel Shepherd
Guest
Posts: n/a
 
      09-07-2003
Thomas Henz wrote:
> Joel Shepherd wrote:
>
>> About the best you can do is have a session on the server side
>> for each user that expires after a certain period of inactivity:
>> e.g., after 10 minutes with no further requests in that session.

>
> How can I do that 10 minutes thing without access to mysql files on
> the providers side? or is that a php session thing (i smell OT)?


It's probably a PHP thing. Hopefully PHP has some way of notifying you
(in code) when a session has expired. Catch that notification, write
something to your database, and move on.

I'm being vague because I haven't used PHP specifically, and in any
event sessions can be and are implemented in many different ways.

--
Joel.

 
Reply With Quote
 
Darren Benfer
Guest
Posts: n/a
 
      09-08-2003
Thomas Henz <(E-Mail Removed)> wrote in news:bjg2fd$i3g$04$(E-Mail Removed)-
online.com:

> Hi!
>
> I'm searching for something that lets me write into a mysql db (or just
> do sth) when a user leaves a site. that means if the user closes the
> browser window. How can I do such a thing? I heard something about a
> <body onleave=""> but it doesn't seem to be implemented in browsers or
> at least some of them.
>
> Thanks,
>
> Tom
>


I don't think there is a way to this within php. My thought is that you
could start a session and log the session-id into mysql for every page
access, then have a cron job that checks for sessions within mysql that
have been inactive for a short while. If it finds one, kill the session and
remove the mysql row. But it seems like an awful lot of work.

The other thing (*shudder*) is to use javascript's onblur or onclose and
open a pop-up to a short php script that does the save, but I wouldn't
recommend it. Pop-ups for such a purpose would be a bit rude!

GL...

--
D Benfer
Mokee.com
USWebSales.com
 
Reply With Quote
 
Thomas Henz
Guest
Posts: n/a
 
      09-08-2003
Darren Benfer wrote:

> The other thing (*shudder*) is to use javascript's onblur or onclose and
> open a pop-up to a short php script that does the save, but I wouldn't
> recommend it. Pop-ups for such a purpose would be a bit rude!


I thought about that for some minutes and came to the same conclusion of
being rude to the user. But since I don't have access to a root server
or sth where I could install automatic scripts...well...why not be rude?
Couldn't I open a new window and close it immediately after executing
the sql command? Something like "when function finished, window.close()"? :/

Tom

 
Reply With Quote
 
Chris Morris
Guest
Posts: n/a
 
      09-08-2003
Thomas Henz <(E-Mail Removed)> writes:
> I thought about that for some minutes and came to the same conclusion
> of being rude to the user. But since I don't have access to a root
> server or sth where I could install automatic scripts...well...why not
> be rude?


You could just assume that they've left when the session isn't being
used anymore.

> Couldn't I open a new window and close it immediately after executing
> the sql command? Something like "when function finished,
> window.close()"? :/


Depending on the speed of the user's computer, this might get in the
way anyway.

Also, pop-up blockers are becoming more commonplace - built in to most
modern browsers, 3rd party ones available for older browsers such as IE.

--
Chris
 
Reply With Quote
 
Andrew Davidson
Guest
Posts: n/a
 
      09-08-2003
"Thomas Henz" <(E-Mail Removed)> wrote in message
news:bjh7ij$hev$02$(E-Mail Removed)-online.com...
> or sth


????

--
Andrew Davidson


 
Reply With Quote
 
Thomas Henz
Guest
Posts: n/a
 
      09-08-2003
Andrew Davidson wrote:

> "Thomas Henz" <(E-Mail Removed)> wrote in message
> news:bjh7ij$hev$02$(E-Mail Removed)-online.com...
>
>>or sth

>
>
> ????
>

sth=something :/

What I wanted to say is that I don't have access to a server shell or
cronjobs etc. that could do things automatically for me.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments