php page add counter
Release: 2016-08-08 09:23:08
Original
1114 people have browsed it
index.php
1php
2 include("counter.php")
3?> 4 5<html> 6<head> 7<title>访问计数器title> 8head> 910<body>11<center>12<h1>访问者计数器h1>13<U>14<font size="6" face="隶书">你是第font>15<B>16<font size="9" face="Verdana" color="#ffcc00">17php Counter() ?>18font>19B>20<font size="6" face="隶书">个访问者font>21U>22center>23body>24html>
counter.php
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 < 10)
23 print "$five"."$num";
24 elseif($num < 100)
25 print "$four"."$num";
26 elseif($num < 1000)
27 print "$three"."$num";
28 elseif($num < 10000)
29 print "$two"."$num";
30 elseif($num < 100000)
31 print "$one"."$num";
32 else
33 print "$num";
34 }
35 $fp = fopen($counter,"w");
36 fputs($fp,"$num");
37 fclose($fp);
38 }
39?>r
The above introduces the PHP page adding counter, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31