アクセスカウンター(今日・昨日)
#! /usr/local/bin/perl
$url = "../../sample/img/no/"; # 画像保存先
$file = "./dat/counttoday.dat"; # カウント保存先ファイル
open(FILE, "+<$file"); # カウントの読み込み
eval{ flock(FILE, 2) };
$count = <FILE>;
($total, $today, $yesterday, $ip, $date2) = split(/\t/, $count); # 分割(トータル、今日、昨日、IP、日付)
if($ENV{'REMOTE_ADDR'} ne $ip) { # IPアドレス確認(同一IPアドレスはカウントしない)
my ($sec, $min, $hour, $date) = localtime(time); # 今日の日付
if($date ne $date2) { # 日付確認(日付がかわった場合)
$yesterday = $today; # 昨日のカウントを$todayの値に変更
$today = 0; # 今日のカウントを0に
}
$total++; # トータルのカウント(+1)
$today++; # 今日のカウント(+1)
seek(FILE, 0, 0); # カウントの書き込み
print FILE "$total\t$today\t$yesterday\t$ENV{'REMOTE_ADDR'}\t$date\t";
}
close FILE;
print qq(Content-type: text/html\n\n); # HTML出力
print qq(<html>\n);
print qq(<head>\n);
print qq(<title>アクセスカウンター</title>\n);
print qq(</head>\n);
print qq(<body>\n);
print qq(<center>\n);
for($i = 0 ; $i < length($total) ; $i++) { # 画像を表示
my $n = substr($total, $i, 1); # 1文字抜き出す
print qq(<img src="$url$n.gif" alt="$n" width="25" height="25">);
}
print qq(<br><small>今日:$today 昨日:$yesterday</small><br>\n);
print qq(</center>\n);
print qq(</body>\n);
print qq(</html>\n);
exit;
〔 実行する 〕