一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php图片计数器代码

时间:2008-11-15 编辑:简简单单 来源:一聚教程网

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('');";   
}

?>

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

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

等吧,我们教程就OK了.

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

热门栏目