Free CGI Perl PHP Script Olive Design CGI

カウンター その2

カウンターの表示部分をgif画像にしました。

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

データ保存用ファイル空ファイルをcount.dat作成し0をセットしておき、パーミションを666にします。

数字のgif画像をこちらからダウンロードして同じフォルダに入れておきます。

サンプル

ソース counter02.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 $count_txt = strval ($count_num); #文字列に変換 $c_echo= strlen ($count_txt); #文字列の長さを返す for ( $i=0 ; $i< $c_echo ; $i++){ $n=substr ($count_txt , $i , 1 );#文字列を一つづつ分解 echo "<img src=${n}.gif>"; } ?> </body> </html>
Perl PHP Free CGI Script OliveDesign CGI

Perl PHP Free CGI Script OliveDesign CGI

OliveDesign CGIプライバシーポリシー