php页面添加计数器
程序员文章站
2024-02-10 18:18:34
...
index.php 1php
2 include("counter.php")
3?> 4 5html> 6head> 7title>访问计数器title> 8head> 910body>11center>12h1>访问者计数器h1>13U>14font size="6" face="隶书">你是第font>15B>16font size="9" face="Verdana" color="#ffcc00">17php Counter() ?>18font>19B>20font size="6" face="隶书">个访问者font>21U>22center>23body>24html> 1php
2 //$five,$four 等变量表示零的个数,放在数字前边构成6位
3 function Counter()
4 { //定义函数
5 $five = "00000"; //声明变量
6 $four = "0000";
7 $three = "000";
8 $two = "00";
9 $one = "0";
10 $counter = "record.dat"; //存放访问数的目的文件,.dat格式
11 if(!file_exists($counter)) //判断文件是否存在
12 {
13 $counter = fopen($counter,"w");
14 fputs($counter,"0"); //写入文件
15 fclose($counter);
16 }
17 else
18 {
19 $fp = fopen($counter,"r+");
20 $num = fgets($fp,"1024"); //如果文件存在则读出文件,并加 1
21 $num = $num + 1;
22 if($num 23 print "$five"."$num";
24 elseif($num 25 print "$four"."$num";
26 elseif($num 27 print "$three"."$num";
28 elseif($num 29 print "$two"."$num";
30 elseif($num 31 print "$one"."$num";
32 else
33 print "$num";
34 }
35 $fp = fopen($counter,"w");
36 fputs($fp,"$num");
37 fclose($fp);
38 }
39?>
counter.php
以上就介绍了php页面添加计数器,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。