4 # A simple counter program which maintains counts for
5 # all files in a single counts file. Some systems may
6 # not allow "." files to be created, so you should
7 # rename the count file.
12 # get name of accessed document
14 $doc = $ENV{'DOCUMENT_URI'};
15 $host= $ENV{'REMOTE_HOST'};
16 $path= $ENV{'PATH_INFO'};
17 $server= $ENV{'SERVER_NAME'};
20 # open counts file for read & write
21 # get an exclusive lock on it
23 open(COUNTS, "+< /usr/lib/cgi-bin/hit_counts") || die("error: can't open hit_counts.\n");
24 flock(COUNTS, 2); # will wait for lock
27 # read counts database into associative array
31 ($count, $file) = split(/:/, $_);
32 $counts{$file} = $count;
35 # strip off silly www hostname bits.
36 if ($server =~ /^www\./) {
37 $server =~ s/^www\.//;
40 # translate some domains into other domains to avoid maintaining multiple
41 # hit count lists for the same sites that have different names.
42 #if ($server =~ /^gruntose\.org/) {
43 # $server =~ s/^gruntose\.org/gruntose.com/;
46 #hmmm: what about koeritz.com / koeritz.org?
49 # increment count of hit document, but not if I'm the
53 #we could do without that line probably.
56 # increment count for this file
58 $counts{$server.$doc}++;
62 # put file marker back at beginning
66 foreach $file (sort {lc $a cmp lc $b} keys %counts) {
67 print COUNTS $counts{$file}, ":", $file, "\n";
73 # print count string to STDOUT
75 print "Content-type: text/plain\n\n";
77 print $counts{$server.$doc};