1.首先在php根目錄下面建三個文件,count.php,count.txt,index.phpphp
2.將count.php裏面添加以下代碼:ide
<?phpit
//選擇 counter.txt文本文件class
$counter_file = ("counter.txt");file
//打開文本文件權限
$visits = file($counter_file);di
//自動加1文件
$visits[ 0]++;view
//這個點擊自動記錄vi
$fp = fopen($counter_file, "w");
//寫入counter.txt文件中,從而記錄了
fputs($fp, "$visits[0]");
//關閉文件
fclose($fp);
//顯示次數
echo $visits[0];
?>
3.把count.txt改爲可寫權限777
4.在index.php中加入以下代碼
<?php
include ("count.php");
?>