PHP Graphics Counter Program display site user browsing _php instance

Source: Internet
Author: User
Tags file copy

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.