程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php寫的網頁計數器代碼

php寫的網頁計數器代碼

編輯:關於PHP編程

<html>
<head>
<title>php教程寫的網頁計數器代碼</title>
<head>
<body>

<?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 "<div align=center><font size=5>計數次數:$count</font><br>";

// 圖形模式計數
$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 "<div align=center><font size=5>計數次數:";
for ($array_id = 1;$array_id < $array_elements; ++ $array_id) {
echo "<img src=countimg/".$counter_array[$array_id].".gif>";
}
echo "</font>";

fclose ($fp);
//並關閉文件
}

?>

</body>
</html>

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved