Something is wrong with this code
it WAS working......
This code is suposed to work from any of my web pages
and count the number of hits to each web page.
the command that calls this is
<!--#exec cmd="/home/homepage/cgi-bin/counter.pl"-->
Just substitute your homepage for the "homepage" throughout the program
#!/usr/bin/perl -w
#<!--#exec cgi="counter.pl"-->
##gets the name of the page it is called from???
$file = "$ENV{'DOCUMENT_URI'}";
if ($file !~ /\w+.htm/) { ## index.htm is the default, but if
$file="/index.htm"; ## unspecified, the script will be
} ## unaware... Env variables are not
## updated by inferences...
if ($ENV{'DOCUMENT_URI'} =~ /homepage/) {
$file = substr($file,length("/~thx-1138"),length($file));
}
##sets file name to web page name????
$file =~ s/\//_/g;
## opens, reads number of hits and closes the file acording to the web page its called
from.
open(FILE,"/home/homepage/cgi-bin/data/$file");
flock (FILE, 2);
$count = <FILE>;
flock (FILE, 8);
close(FILE);
## adds a hit to the variable
$count++;
## opens, prints the new total of hits and closes the file.
open(FILE,">/home/homepage/cgi-bin/data/$file");
flock (FILE, 2);
print FILE "$count";
flock (FILE, 8);
close(FILE);
## prints this to my web page as a blue dash, green number of hits, blue dash
printf "<font color=\"blue\">-(</font><font color=\"green\">$count</font><font
color=\"blue\">)-</font>";
## Not sure what this does, I think its supposed to
## keep a list of who visited my web page.
open(A,">>/home/homepage/cgi-bin/data/refs.htm");
print A "$ENV{'HTTP_REFERRER'}\n";
close (A);
exit;