当前位置:编程学习 > php >>

php 文件计数据器+mysql双保护

php 文件计数据器+mysql双保护,这是上次升级版了,上次流量大太经常出问题今天修改过来了.

<?php
 require_once("../inc/connect.php");
 Class Sit_count{
   public $FileName = 'count.txt'; 
  function Count_add(){
   if(file_exists($this->FileName) ){
    $Temp = file_get_contents($this->FileName);    
    $Array = explode("=",$Temp); 
    if(count($Array) != 2){   
     $Tmp ='mytext='.$this->Tcount();
    }else{
     $Total = $Array[1]+1;  
     $Tmp =$Array[0].'='.$Total;      
    }
    $T = @fopen($this->FileName,'w');
    if($T){
     fwrite($T,$Tmp);
     fclose($T);
    }
    mysql_query("update wk_count set count_bak =count_bak+1 where id=1");
   }else{
    echo '! file_exists';
   }
   
  }
 
  function Tcount(){
    $result =mysql_query("Select * from wk_count where id =1 ") or die(mysql_error());
   $rs =mysql_fetch_array($result);
   return $rs['count_bak'];
   
  }
 }
  $tp = new Sit_count;
  $tp->Count_add();
?>
本站原创转载注明www.226511.com/phper/php.html

补充:Php教程,Php常用代码 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,