I think there is a little confusion here. It is not useful
to pass query arguments to a cgi-bin script this way, because
you will get the literal string $document.
Here is a complete solution:
Put this line in every page that you want to be counted:
<!--#include virtual="/cgi-bin/counter.pl" -->
Those pages shuold have extensions .shtml
The code for counter.pl is:
#!/usr/bin/perl
use Fcntl qw(:DEFAULT :flock);
use Digest::MD5 qw( md5_base64 );
use strict;
use vars qw( $referer $counter_file $ofh $num );
$referer = $ENV{DOCUMENT_URI};
$counter_file = "/home/httpd/(your_site)/var/counter/". md5_base64($re
+ferer);
sysopen(FH, $counter_file, O_RDWR | O_CREAT) or die "can't open numfil
+e: $!";
$ofh = select(FH);
$| = 1;
select ($ofh);
flock(FH, LOCK_EX) or die "can't write-lock numfile: $!";
$num = <FH> || 0;
seek(FH, 0, 0) or die "can't rewind numfile : $!";
print FH $num+1, "\n" or die "can't write numfile: $!";
truncate(FH, tell(FH)) or die "can't truncate numfile: $!";
close(FH) or die "can't close numfile: $!";
print "Content-type: text/html\r\n\r\n";
print "Counter for $referer is $num\n";
We can't use HTTP_REFERER because we are not a page, we are
a sort of subrequest. The code for the counter is taken from
perlopentut.
Hope this clarifies the problem. Ciao, Valerio |