For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > August 2005 > onunload is a great function but it generates popups!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author onunload is a great function but it generates popups!
Martin

2005-08-24, 6:55 pm

Does anyone know a way to use the htm <body onunload=foo()> function
to execute a php script without creating another window (popup). This
has some real applications for tracking visitors and getting accepted
by the google monster.

I am simply trying to write (append) a file with information on exit
from my web site. Seems like that should not be a big deal.


Philip Ronan

2005-08-24, 6:55 pm

"Martin" wrote:

> Does anyone know a way to use the htm <body onunload=foo()> function
> to execute a php script without creating another window (popup). This
> has some real applications for tracking visitors and getting accepted
> by the google monster.
>
> I am simply trying to write (append) a file with information on exit
> from my web site. Seems like that should not be a big deal.


Change the offsite links so that they point to a local redirection script.
For example, change <A href="http://site2.example.com/"> into something like
<A href="/redirect.php?to=http%3A//site2.example.com/">.

In the redirect.php script, do whatever you have to, and then issue a
redirect header like this:

<?php header("Location: " . $_GET['to']); ?>

More info -> <http://php.net/header>

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/


Colin McKinnon

2005-08-25, 3:55 am

Martin wrote:

> Does anyone know a way to use the htm <body onunload=foo()> function
> to execute a php script without creating another window (popup). This
> has some real applications for tracking visitors and getting accepted
> by the google monster.
>
> I am simply trying to write (append) a file with information on exit
> from my web site. Seems like that should not be a big deal.


Hmm intersting not seen that one b4.

You could set the src of an img or an iframe. Of course you'd need to give
the page enough time to send the request before allowing it to go
elsewhere.

I'd be interested to hear how you solve this one.

C.
Lāʻie Techie

2005-08-26, 3:55 am

onunload is client side whereas PHP executes on the server. There is no
way for PHP to know when a browser has left a certain page or closed the
window. Most forums keep track of the last time a client was active then
display a list of members active within a "reasonable" amount of time
(normally 30 minutes).

HTH,
Laie Techie


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com