Who Clicks Where
Every click on a web page is important. To
maintain a good, useful web site you need to keep track of what works
and what doesn't work for your visitors. By looking at the web server's
Log Files,
you can get a better idea of how people use your web site.
However, when you provide links to other web sites, like this, this or even this, you'd like to know when someone clicks on the link.
Well, here's a simple Perl script that will let you do just that.
Here's how to use the script:
- Edit the script and change the
filename "/tmp/redirect.log" to point someplace where you want to
store the log. (You'll need to make sure that the file can be written
to by the httpd server process; a simple but unsafe solution is
chmod a+w /tmp/redirect.log)
- Copy the script to the /cgi-bin directory. Type chmod a+x redirect.pl to make it executable.
- On a web page, enter the following HTML:
<a href="/cgi-bin/redirect.pl?http://www.yahoo.com">Surf to Yahoo</a>
- Now, view that web page in your browser. Click on the link Surf to Yahoo and you should be redirected to Yahoo's web site. At the same time, an entry should appear in /tmp/redirect.log listing the time, your IP address and the destination.
Now, try it out online (if my web server is online):
And, click here to view the log of people who've been redirected:
Finally, you can modify the contents of the log by changing the following line in redirect.pl:
print F "$date - $ENV{'REMOTE_ADDR'} => $toURL\n";
This line includes the current date $date, the user's IP address $ENV{'REMOTE_ADDR'} and the destination URL $toURL.
You can use it to include just the information that you want in a
format that's useful.
Date: [03/31/98]
More articles about CGI
More articles by Doug
Steinwand
Author Biography