php教程寫的網頁計數器代碼
$countfile = "counter.txt";
//定義計數器寫入的檔案是目前的目錄下的counter.txt檔案中,然後我們應當測試該檔案能否開啟
if (($fp = fopen($countfile, "r+")) == false) {
//用讀寫入模式開啟檔案,若不能開啟就退出
printf ("open file %s failed!",$countfile);
exit;
}
else
{
//如果檔案能夠正常開啟,就讀入檔案中的資料,假設是1
$count = fread ($fp,10);
//讀取10位元據
$count = $count + 1;
//count ++
fclose ($fp);
//關閉當前檔案
$fp = fopen($countfile, "w+");
//以覆蓋模式開啟檔案
fwrite ($fp,$count);
//寫入加1後的新資料
fputs($fp,$fg);
//顯示計數結果
// 數字顯示
echo "計數次數:$count
";
// 圖形模式計數
$fp = fopen ($countfile, "r"); //以唯讀模式開啟檔案
$array_count = 1; //定義一個表示數組元素位置的變數,下面要用
while (! feof($fp)) {
$current_number = fgetc($fp);
$counter_array[$array_count] = $current_number;
$array_elements = count ($counter_array);
$array_count = $array_count + 1;
}
echo "計數次數:";
for ($array_id = 1;$array_id < $array_elements; ++ $array_id) {
echo "";
}
echo "";
fclose ($fp);
//並關閉檔案
}
?>
http://www.bkjia.com/PHPjc/632038.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632038.htmlTechArticlehtml head titlephp教程寫的網頁計數器代碼/title head body ?php $countfile = counter.txt; //定義計數器寫入的檔案是目前的目錄下的counter.txt檔案中,然後我...