#!/usr/bin/perl require './gifcat.pl'; $base = './cntdata'; #データ格納ディレクトリ $totalfile = "$base/total.txt"; #カウンタ $lastfile = "$base/last.txt"; $lockfile = "$base/lock"; ### メイン処理 ### &lock; $addr = $ENV{'REMOTE_ADDR'}; open (IN,"$lastfile") || &error("OPEN ERROR"); $paddr = ; close IN; if ($addr ne $paddr) { open (OUT,">$lastfile") || &error("OPEN ERROR"); print OUT $addr; close OUT; open (IN,"$totalfile") || &error("OPEN ERROR"); $total = ; close IN; $total++; open (OUT,">$totalfile") || &error("OPEN ERROR"); print OUT $total; close OUT; } &unlock; open (IN,"$totalfile") || &error("OPEN ERROR"); $total = ; close IN; $size = length($total); if ($size < 4) {$total = sprintf("%04d",$total); $size = 4;} print "Content-type: image/gif\n\n"; @img = (); for (0 .. $size-1) { $n = substr($total,$_,1); $n = "$base/$n.gif"; push (@img,$n); } binmode(STDOUT); print &gifcat'gifcat(@img); exit; ### sub lock { $retry = 3; if (-e $lockfile) { $locktime = (stat($lockfile))[9]; if ($locktime < time - 60) {&unlock;} } while (!mkdir($lockfile, 0755)) { if (--$retry < 0) {&error("busy!");} sleep(1); } } ### sub unlock {rmdir($lockfile);} ### sub error {exit;}