亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        php實現計數器方法小結

        字號:


            本文實例講述了php實現計數器的方法。分享給大家供大家參考。具體如下:
            這里收藏了三款php計數器代碼,他們三個都有一個同共點就是全部無需數據庫,而是利用了文本文件來實現網頁瀏覽計數.
            第一款PHP計數器代碼如下:
            復制代碼 代碼如下:<?php
            //計數器
            function countx($file="count.dat"){
            if(file_exists($file)){
            $fp=fopen($file,"r");
            $numx=fgets($fp,10);
            fclose($fp);
            $numx++;
            //以上四行代碼可以用一條表達式代替:$numx=file_get_contents($file)+1;
            }
            else{
            $numx=1;}
            file_put_contents($file,$numx);//當文件不存在時,這函數會自動創(chuàng)建文件,而且會自動把參數轉成字符串寫入。
            echo $numx;
            /*整個函數體可以用兩條表達式代替:file_exists($file)?file_put_contents($file,file_get_contents($file)+1):file_put_contents($file,"1");readfile($file);
            */
            }
            //函數調用
            countx();
            ?>
            第二款PHP計數器,代碼如下:
            復制代碼 代碼如下:<?php
            $counterfile = "balong.txt";//存儲數值的文件名幾路徑
            function displaycounter($counterfile) {
            $fp = fopen($counterfile,"rw");
            $num = fgets($fp,5);
            $num += 1;
            print "您是第 "."$num"." 個看巴瀧計數器的家伙";
            exec( "rm -rf $counterfile");
            exec( "echo $num > $counterfile");
            }
            if (!file_exists($counterfile)) {
            exec( "echo 0 > $counterfile");
            }
            displaycounter($counterfile);
            ?>
            第三款PHP計數器代碼如下:
            復制代碼 代碼如下:<?php
            $counterfile = "存儲數值的文件名幾路徑
            function displaycounter($counterfile) {
            $fp = fopen($counterfile,"rw");
            $num = fgets($fp,5);
            $num += 1;
            print "您是第 "."$num"." 個看巴瀧計數器的家伙";
            exec( "rm -rf $counterfile");
            exec( "echo $num > $counterfile");
            }
            if (!file_exists($counterfile)) {
            exec( "echo 0 > $counterfile");
            }
            displaycounter($counterfile);
            ?>
            希望本文所述對大家的php程序設計有所幫助。