アクセスカウンター(画像)
<html> <head> <title>画像アクセスカウンター</title> </head> <body> <center> <?php $img = "../../sample/img/no"; // 画像保存先フォルダ if($file = fopen("./dat/count.dat", "r+")) { // ファイルを開く flock($file, LOCK_EX); // ファイルロック $count = fgets($file); // カウント読み込み $count++; // カウント+1 rewind($file); // ポインタを先頭に fputs($file, $count); // ファイル書き込み flock($file, LOCK_EX); // ファイルロック解除 fclose($file); // ファイルを閉じる echo "あなたは \n"; // カウント表示 for($i = 0 ; $i < strlen($count) ; $i++) { // 画像を表示 $n = substr($count, $i, 1); // 1文字抜き出す echo "<img src=\"$img/$n.gif\" alt=\"$n\" width=\"25\" height=\"25\">\n"; } echo " 人目の訪問者です\n"; } ?> </center> </body> </html>
〔 実行する 〕