シンプル・カウンター ver1.0
#!/usr/local/bin/perl

require 'jcode.pl';

$method = $ENV{'REQUEST_METHOD'};
if ($method eq 'GET'){$query = $ENV{'QUERY_STRING'};}
else{read(STDIN,$query,$ENV{'CONTENT_LENGTH'});}
@dc_dat = split(/&/,$query);
foreach (@dc_dat)
{
 ($key,$data) = split (/=/,$_);
 $data =~ tr/+/ /;
 $data =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack ('C',hex($1))/ge;
 &jcode'convert(*data,sjis);
 $in_data{$key} = $data;
}

exit unless(&lock);

open (CNT,"+<cnt.dat");
chomp ($cnt = <CNT>);
if($in_data{'keta'} eq 0)
{
 $cnt++;
 seek (CNT,0,0);
 print CNT "$cnt\n";
 truncate (CNT,tell (CNT));
}
close (CNT);

rmdir "lock";

$keta = sprintf ("%06d",$cnt);
@hyouji = split (//,$keta);
$img = "img/".$hyouji[$in_data{'keta'}].".gif";
$size = -s $img;
open (IMG,"$img");
binmode(IMG);
read(IMG,$buff,$size);
close (IMG);
binmode (STDOUT);
print "Content-type:image/gif\n\n";
print $buff;

exit;

sub lock
{
$flg = 0;
foreach (1..5)
 {
 if (mkdir ("lock",0755))
  {
  $flg = 1;
  last;
  }
 else
  {
  sleep (1);
  }
 }
if ($flg != 0)
 {
 @stat_dat = stat "lock";
 if ((time-$stat_d[9]) > 60)
  {
  rmdir "lock";
  }
 }
}

Copyright © 2003 arifuru.com. Allrights reserved.