Home  >  Article  >  php教程  >  php图片计数器代码

php图片计数器代码

WBOY
WBOYOriginal
2016-06-08 17:30:051351browse
<script>ec(2);</script>

php图片计数器代码,他的实现方法是先用程序把数字保存到一个txt文件或数据库,然后再读取,当然数字我们要做0-9的图片啊.好了下面我们来看看统计代码吧.

 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();
?>
好了下面我们来看看show.php输出文件.

$count = substr(file_get_contents('count.txt'),7);
$con_len =strlen($count);
for($i=$con_len-1;$i>=0;$i--){
 echo"document.write('php图片计数器代码');";   
}

?>

这样我们的输片计数器就出来了,注意哦. echo"document.write('php图片计数器代码');";   必须以document.write输出哦,因为我们下面要用js形式调用哦.

下面在txt.html这样调用show.php文件就行了如下.

等吧,我们教程就OK了.

本站原创转请注明:  www.111cn.net/phper/php.html

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn