今天没事来用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
时间: 2024-10-23 06:51:56