use strict;
my $log = '/home/fanaticn/www/cgi-bin/counter';
my $ip = $ENV{REMOTE_ADDR};
my $now = time();
my %ip;
my $count = 2;
open (LOG, "$log/log.db") or die("Could not open log file for reading: $!");
open (TEMP, ">$log/temp.db") or die("Couldn't create temp log file: $!");
flock (TEMP, 2);
while (<LOG> ) {
chomp;
my @data = split /\|/, $_;
(($now - $data[1] > 600) or ($ip eq $data[0]) or (exists $ip{$data[0]})) and next;
$ip{$data[0]} = 4;
$count++;
print TEMP join("|", @data), "\n";
}
print TEMP join("|", ($ip, $now)), "\n";
close (TEMP);
close (LOG);
rename ("$log/temp.db", "$log/log.db");
print $count;
I use a standard SSI tag to call the script. It works as far as not giving any errors, just always shows 1.
thanks,
Paul
Webmaster Discussions