国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

三款php計數(shù)器代碼

2024-05-04 21:48:54
字體:
供稿:網(wǎng)友

文章收藏了三款php計數(shù)器代碼,他們?nèi)齻€都有一個同共點就是全部無需數(shù)據(jù)庫,而是利用了文本文件來實例網(wǎng)頁瀏覽計數(shù).

第一款PHP計數(shù)器代碼如下:

  1. <?php  
  2. //計數(shù)器  
  3. function countx($file="count.dat"){  
  4. if(file_exists($file)){  
  5. $fp=fopen($file,"r");  
  6. $numx=fgets($fp,10);  
  7. fclose($fp);  
  8. $numx++;  
  9. //以上四行代碼可以用一條表達式代替:$numx=file_get_contents($file)+1;  
  10. }  
  11. else{  
  12. $numx=1;}  
  13. file_put_contents($file,$numx);//當(dāng)文件不存在時,這函數(shù)會自動創(chuàng)建文件,而且會自動把參數(shù)轉(zhuǎn)成字符串寫入。  
  14. echo $numx;  
  15. /*整個函數(shù)體可以用兩條表達式代替:file_exists($file)?file_put_contents($file,file_get_contents($file)+1):file_put_contents($file,"1");readfile($file);  
  16. */  
  17. }  
  18. //函數(shù)調(diào)用  
  19. countx();  
  20. ?> 

第二款PHP計數(shù)器,代碼如下:

  1. <?php  
  2.     
  3.     
  4.   $counterfile = "balong.txt";//存儲數(shù)值的文件名幾路徑  
  5.     
  6.   function displaycounter($counterfile) {  
  7.    $fp = fopen($counterfile,"rw");  
  8.    $num = fgets($fp,5);  
  9.    $num += 1;  
  10.    print "您是第 "."$num"." 個看巴瀧計數(shù)器的家伙";  
  11.    exec"rm -rf $counterfile");  
  12.    exec"echo $num > $counterfile");  
  13.   }  
  14.     
  15.   if (!file_exists($counterfile)) {  
  16.    exec"echo 0 > $counterfile");  
  17.   }  
  18.     
  19.   displaycounter($counterfile);  
  20.     
  21.   ?> 

第三款PHP計數(shù)器代碼如下:

  1. <?php  
  2.     
  3.     
  4.   $counterfile = "m.survivalescaperooms.com.txt";//存儲數(shù)值的文件名幾路徑  
  5.     
  6.   function displaycounter($counterfile) {  
  7.    $fp = fopen($counterfile,"rw");  
  8.    $num = fgets($fp,5);  
  9.    $num += 1;  
  10.    print "您是第 "."$num"." 個看巴瀧計數(shù)器的家伙";  
  11.    exec"rm -rf $counterfile");  
  12.    exec"echo $num > $counterfile");  
  13.   } //開源代碼Vevb.com 
  14.     
  15.   if (!file_exists($counterfile)) {  
  16.    exec"echo 0 > $counterfile");  
  17.   }  
  18.     
  19.   displaycounter($counterfile);  
  20.     
  21.   ?>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 淄博市| 叙永县| 利辛县| 陆河县| 平谷区| 纳雍县| 敖汉旗| 重庆市| 滨海县| 德阳市| 贞丰县| 宜昌市| 会昌县| 柳林县| 赤城县| 安泽县| 多伦县| 普宁市| 延长县| 会宁县| 甘谷县| 东海县| 白水县| 剑河县| 三门县| 银川市| 湾仔区| 林州市| 临西县| 石家庄市| 德清县| 杭锦后旗| 无极县| 鲜城| 丰顺县| 同仁县| 土默特左旗| 瓦房店市| 东莞市| 合川市| 张掖市|