the complete webmaster
tutorials reviews reference
ASP
CGI
FrontPage
HTML
Java
JavaScript

Sponsored by El Scripto

Visit the Mortgage Loan Place for Home Loans and also click here to find VA Loans on our site.

Get thousands of people selling your product online for FREE

home / articles / cgi

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.

Download This Week's Script - redirect.pl

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):

Jump to Yahoo.com

And, click here to view the log of people who've been redirected:

View Redirection Log

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.

Author: Doug Steinwand
Date: [03/31/98]
More articles about CGI
More articles by Doug Steinwand
Author Biography
Promote your website
write for us about us advertise

Copyright 1997, 1998 A Big Lime. All rights reserved.