Heres my sample code for doing a redirect from a link on a website, logging the redirect, and later checking the counts of the redirects.  Please keep in mind that this is only a code example, and while it does work on my site, there is no warranty implied, nor do I endorse this code as being fit for merchantability for any purpose.  USE THIS CODE AT YOUR OWN RISK!

The webpage with the links

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test Page</title>
</head>
<body>

<A HREF=/cgi-bin/redirect.pl?url=http://www.yahoo.com/>Visit Yahoo!</A><br>
<A HREF=/cgi-bin/redirect.pl?url=http://www.lycos.com/>Visit Lycos</A><br>
<A HREF=/cgi-bin/redirect.pl?url=http://www.google.com/>Visit Google</A><br>
<A HREF=/cgi-bin/redirect.pl?url=http://www.netscape.com/>Visit Netscape</A><br>
<A HREF=/cgi-bin/redirect.pl?url=http://www.cnn.com/>Visit CNN</A><br>

</body>
</html>

The Perl redirect script

#!/usr/bin/perl
#
# Script to redirect url's
# while counting said redirects
#

# Tested with Netscape3.6/NT4.0/ActivePerl 5.13 with a server cgi-bin,
# Tested with Netscape2.0/Solaris2.6/Perl 5.005_02 without server cgi-bin,
#

$local_dir = "\/your\/local\/cgi_bin\/";

&html_content;
&work;
&do_html;

sub work{
$my_file = "$local_dir$filename";
open(COUNT,"$my_file");
$count = (<COUNT>);
close (COUNT);
$count = $count + 0;
++$count;
open (COUNT, "> $my_file");
print COUNT "$count \n";
close(COUNT);
}

sub do_html{
$refresh_string = '<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=';
$tail = '">';
print "<html>\n";
print "<body>\n";
print "$refresh_string$url_string$tail\n";
#print "$url\n"; #for testing, uncomment this line and comment the line above
print "</body>\n";
print "</html>\n";
}

sub html_content{
$QUERY_STRING = $ENV{"QUERY_STRING"};
@NameValuePairs = split (/&/, $QUERY_STRING);
foreach $NameValue (@NameValuePairs){
       ($Name, $url_string) = split (/=/, $NameValue);
       $url_string =~ tr/+/ /;
       $url_string =~ s/%([\dA-Fa-f][\dA-Fa-f])/ pack ("C", hex ($1))/eg;
       @fields = split ( /\/\//, $url_string);
       $url = $fields[1];
       $url =~ tr/\./_/;
       $url =~ tr/\// /;
       $filename = "$url.txt";
       }
}




The Perl count script

#!/usr/bin/perl
#
# Script to count number
# of redirected url's
#
# Tested with NetscapeEnt3.6/NT4.0/ActivePerl 5.13 with a server cgi-bin,
# Tested with NetscapeEnt2.0/Solaris2.6/Perl 5.005_02 without server cgi-bin,
#

$local_dir = "\/your\/local\/cgi_bin\/";
$filename = "redirs.cnt";

$my_file = "$local_dir$filename";

print "$my_file\n";
&open_html;
&what_I_had;
&close_html;

sub open_html{
print "<html>\n";
print "<body>\n";
print "<br><br><blockquote><blockquote><blockquote><blockquote><blockquote><blockquote>\n";
print "<font size=+2 face=Tohama,Arial><b> This page lists the counts of redirections that your server has done.</b></font><br><br><br>\n";
print "<font size=+1 face=Tohama,Arial}\n";
}

sub close_html{
print "</blockquote></blockquote></blockquote></blockquote>\n";
print "</body>\n";
print "</html>\n";
}

sub what_I_had {
$smeg = 1;
opendir(REDIR,"$local_dir");# or die "Cant open $local_dir";
foreach $name (sort readdir (REDIR)){
        $txt_file = "$local_dir$name";
        $off_set = 0; $off_set = index($name,"txt");
        if ($off_set >= 2){
           open(COUNT,"$txt_file");# or warn "Cant open $name\n";
           $count = (<COUNT>);
           close (COUNT);
           $count = ($count + 0);
           $url = $name;
           $url =~ s/\W.*//;
           $url =~ tr/_/\./;
           print "<br>$count redirects to $url\n";
           }
        ++ $smeg;
        $off_set = 0; $count = 0;
        }
closedir (REDIR);
}






Care to email me?  amonotod@netscape.net



1