PHP Graphics Counter Program is a simple picture counter, in order to visually show how many users browsing the Web site, you need to put a picture counter at the bottom of the page, that is, the current page access volume, traffic data is saved in TXT file, can automatically generate num.txt files, Custom initial data , the display of digital pictures saved in the IMG directory, can be replaced by their own exquisite pictures, replacement can be, index.php is called file , very simple.
This program is only dozens of KB, the system code design is easy to understand.
The effect is as follows:
The installation of the program is simple:
1, the graphics counter does not require the support of the database, as long as you can run PHP can be index.php in the php file copy to the desired page can be, other files do not move.
2, the structure of the document:
(1), index.php, call counter file
<?php
echo "You are the first";
Require ("count.php");
echo "Guest";
? >
(2), count.php the core code of the graphics counter
<?php
$path = "img";//the folder where the picture is located, the IMG is under the corresponding folder
$f _name = "num.txt";//The data of the counter is kept in num.txt
$n _digit = ten;
If the file does not exist, create a new file with the initial value of 100/
if (!file_exists ($f _name)) {
$fp =fopen ($f _name, "w");
Fputs ($FP, "the");
Fclose ($FP);
$FP =fopen ($f _name, "R"); Open the Num.txt file
$hits =fgets ($fp, $n _digit);//Start counting Data
fclose ($FP);//close file
$hits = (int) $hits + 1;//counter increase 1
$hits = (string) $hits;
$FP =fopen ($f _name, "w");
Fputs ($fp, $hits);//write New Count
fclose ($FP);//Close file
//loop Read and display graphics counter for
($i =0; $i < $n _digit; $i + +)
$hits = Str_replace ("$i", "
(3) Num.txt Save the Count of files
Traffic data is stored in TXT file, can automatically generate num.txt files, custom initial data
(4) img/save 0-9 of graphics files
Download the source code, start your PHP picture counter system learning Trip bar!
Small hint: The system development is not perfect, there are many deficiencies, but will continue to improve.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.