#!/usr/bin/perl
print "Content-type:text/html\n\n";
$filename = "counter.txt";
$filenamet = "tracker.txt";
open(file,"$filename");
&lockfile(file); @getrec = <file>; &unlockfile(file);
close(file);
($sec,$min,$hr,$day,$month,$year,$dofw,$dofy,$some) = localtime(time);
$q = $ENV{'QUERY_STRING'};
if (!@getrec || $q eq "restart") {
$cnt = 0;
open(file,">$filenamet");
&lockfile(file); print file $ENV{'REMOTE_ADDR'},",",$day+1,"\n"; &unlockfile(file);
close(file);
} else {
$cnt = $getrec[0] + 1;
}
open(file,">$filename");
&lockfile(file); print file $cnt; &unlockfile(file);
close(file);
print $cnt;
sub lockfile {
local($file)=@_;
flock($file,2);
}
sub unlockfile {
local($file)=@_;
flock($file,8);
}
จำนวน : 29 บรรทัด