今天沒事來用php+txt現實現一個網站計數器程序,代碼我們主要用file_get_content 與fopen,fwrite讀寫就OK了.
<?php
Class Sit_count{
public $FileName = 'count.txt';
function Count_add(){
if(file_exists($this->FileName) ){
$Temp = file_get_contents($this->FileName);
$Total = $Temp+1;
echo $Total;
$T = fopen($this->FileName,'w');
fwrite($T,$Total);
fclose($T);
}else{
echo '! file_exists';
}
}
}
$tp = new Sit_count;
$tp->Count_add();
?>
代碼很簡單吧,不過這晨count.txt文件要自己建一個哦,好了宣傳一下站吧本站原創轉載請注明www.111cn.net/phper/php.html