文章收藏了三款php计数器代码,他们三个都有一个同共点就是全部无需数据库,而是利用了文本文件来实例网页浏览计数.
第一款PHP计数器代码如下:
- <?php
-
- function countx($file="count.dat"){
- if(file_exists($file)){
- $fp=fopen($file,"r");
- $numx=fgets($fp,10);
- fclose($fp);
- $numx++;
-
- }
- else{
- $numx=1;}
- file_put_contents($file,$numx);
- echo $numx;
-
-
- }
-
- 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 = "www.phpfensi.com.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);
-
- ?>
|