i made a PHP-Text Counter for i-mode. when we access the net by mobile phones, the host name/ip address is frequently changed. so i use ‘USER_AGENT’ and ‘TIME’ elements for preventing double-count. like this.
<?php
$filename = “./counter.dat”; // datのパス
$UA = htmlspecialchars($_SERVER[‘HTTP_USER_AGENT’]);//ユーザーエージェントの取得
if (strncmp($UA, “Mozil”, 5) <>0 && strncmp($UA, “Opera”, 5) <>0 && strncmp($UA, “Lynx/”, 5) <>0 && strncmp($UA, “HotJa”, 5) <>0) {
$HIJI = date(“U”);//アクセス年月日時刻の取得
$file = fopen($filename,”r+”);
flock($file, 2);
$count = fgets($file,256);//直前のカウント数の取得
$lastUA = fgets($file,256);//直前のユーザーエージェントの取得
$lastHIJI = fgets($file,256);//直前のアクセス年月日時刻の取得
$count = chop($count);
$lastUA = chop($lastUA);
$lastHIJI = chop($lastHIJI);
$dffrHiJI = $HIJI – $lastHIJI;
if($lastUA != $UA) //ユーザーエージェントが直前のものと異なる場合カウントアップ
{$count = $count + 1;
$lastUA = $UA;
$lastHIJI = $HIJI;
} elseif($dffrHiJI > 1200) //ユーザーエージェントが直前のものと同じでも20分以上経っている場合はカウントアップ
{$count = $count + 1;
$lastHIJI = $HIJI;}
ftruncate($file,0);
rewind($file);
fwrite($file, $count);
fwrite($file, “\n”);
fwrite($file, $lastUA);
fwrite($file, “\n”);
fwrite($file, $lastHIJI);
flock($file, 3);
fclose($file);
}
?>
The recipe for sweet potato yōkan that I often made this fall. Ingredients Sweet potato…
After a long time, when I checked broken links and fixed them, I got an…
I made a box, so I prepare the contents. Theme and Plugins. The theme is…
Hehe, it's been almost a year since my last post. I received a notification email…
About a week ago, I finally started to renew my sites, which I had been…
This website uses cookies.