Free CGI Perl PHP Script Olive Design CGI

シンプルカウンター

シンプルなアクセスカウンターです。

ファイル名counter.phpを作成し、下のソースを貼り付けて設置します。

カウントログ保存用のファイルcount.datを作成して0を入力しておく。またパーミッションを666にして同じフォルダに入れておきます。

サンプル

ソース counter.php

<?php
//カウント保存ファイル名を定義
$count_file = "count.dat";
//カウント保存ファイルを読み込み専用でオープンする(r)
$r_count = fopen ($count_file,"r");
//読み込み用ファイルロック
flock ( $r_count,1);

$count_txt =fread ($r_count, filesize($count_file));
//ファイルロック解除
flock ($r_count,3);
//カウント保存ファイルを閉じる
fclose ($r_count);



//カウント数から空白を取り除く
$count_txt = rtrim ($count_txt);
//カウント数を数字に変換
$count_num = intval ($count_txt);
//カウント数を1上げる
$count_num++;

//カウント書き込み処理
//カウント保存ファイルを書き込み専用でオープン(w)
$w_count=fopen ($count_file,"w");
//書き込み用ファイルロック
flock($w_count,2);

//カウント数の書き込み
fwrite ($w_count,$count_num);

//ファイルロック解除
flock($w_count,3);

//ファイルを閉じる
fclose($w_count);

//html表示
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=Shift_JIS"> </head> <body> <?php echo "あなたは${count_num}人目です。" ?> </body> </html>
Perl PHP Free CGI Script OliveDesign CGI

Perl PHP Free CGI Script OliveDesign CGI

プライバシーポリシー / 特定商取引法に基づく表示