3分クッキング
エイプリルフールネタに必要だったので作った超超簡易PV(Page_View)カウンター。
F5でガンガンカウント値が増えるよ!!
<?php $file_name = "count.txt"; //ログ用のファイル名 $is_file = file_exists($file_name); //ファイルの存在をチェック if($is_file==false){ $count = 0; //ファイルが存在しなければ0としてスタート }else{ $count = file_get_contents($file_name); //存在すれば保存されている数字を変数へ格納 } $count++; // アクセスの度に+1する file_put_contents($file_name,$count);//ファイルへ保存。 print "アクセス数".$count."回"; ?>
はい、わずか10行で作ったPVカウンター。
アクセスカウンターと言うよりPV数カウンターと言った方が正しいよね。
更に短くして表示を含め4行。197バイト。
<?php $file_name = "count.txt"; file_exists($file_name)==false ? $count = 0 : $count = file_get_contents($file_name); file_put_contents($file_name,$count+1); print "アクセス数".($count+1)."回"; ?>