Access count:#!/usr/bin/perl $log='counts.log'; $iplog='ips.log'; $lastip='lastip.log'; $host=$ENV{'REMOTE_ADDR'}; $path=$ENV{'DOCUMENT_URI'}||$ENV{'REQUEST_URI'}; print "Content-Type: text/html\n\n"; my $sameip=0; open(LASTIP,"+<$lastip"); flock(LASTIP,2); $lastrec=; ($lasthost,$lastpath,undef)=split(/\|/,$lastrec); if (($lasthost eq $host) && ($lastpath eq $path)){$sameip=1;} if ($sameip eq 0) { seek(LASTIP,0,0); truncate(LASTIP,0); $lastrec=join('|',$host,$path,"\n"); print LASTIP $lastrec; } flock(LASTIP,8); close(LASTIP); open(CNT,"+< $log"); flock(CNT,2); @count=; for($el=0;$el<=$#count;$el++) { ($ct,$rec,undef)=split(/\|/,$count[$el]); if($fnd=($path eq $rec)) { if ($sameip eq 0) {$count[$el]=join('|',++$ct,$rec,"\n");} else {$count[$el]=join('|',$ct,$rec,"\n");} last; } } push(@count,join('|',$ct='1',$path,"\n")) unless $fnd; seek(CNT,0,0); truncate(CNT,0); print CNT sort{($b=~/(\d+)/)[0]<=>($a=~/(\d+)/)[0]} @count; flock(CNT,8); close(CNT); print $ct; my $found=0; open(IPR,"< $iplog"); flock(IPR,1); while() { chomp; last if $found=($_ eq $host); } flock(IPR,8); close(IPR); unless($found) { open(IPW,">> $iplog"); flock(IPW,2); print IPW $host,"\n"; flock(IPW,8); close(IPW); }