use strict; use Fcntl ':flock'; my ($mday,$mon,$year) = (localtime(time))[3,4,5]; $year=$year+1900; if ($mday < 10) {$mday = "0$mday";} if ($mon < 10) {$mon = "0$mon";} my $month = ++$mon; my $date = "$mday.$month.$year"; my $file = "counter.txt"; my $host = $ENV{'REMOTE_HOST'}; my $ip = $ENV{'REMOTE_ADDR'}; my ($uq,@counter,@counter_data); open(COUNTER, "$file") || &error("cannot open file for read"); @counter = <COUNTER>; close(COUNTER); for(@counter) { chomp; @counter_data = split (/\|/, $_); if ($counter_data[0] eq $date && $counter_data[1] eq $ip && $counter_d +ata[2] eq $host) { $uq = 1; } } if (!$uq) { open (COUNTER, ">>$file") || &error("cannot open file for write"); flock (COUNTER, 2); print COUNTER "$date|$ip|$host\n" or die; close(COUNTER) or die; } sub error { my $error = $_[0]; print "$error\n"; exit; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: simple IP counter..
by Juerd (Abbot) on Apr 27, 2002 at 21:21 UTC | |
Re: simple IP counter..
by Anonymous Monk on Aug 31, 2009 at 10:30 UTC | |
by ww (Archbishop) on Aug 31, 2009 at 11:07 UTC |