php寫的網頁計數器代碼_PHP教程

來源:互聯網
上載者:User


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檔案中,然後我...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.