PHP graphic counter program displays the number of user views and counter views

Source: Internet
Author: User

PHP graphic counter program displays the number of user views and counter views

The PHP graphic counter program is a simple image counter. To intuitively display the number of users who browse a website, you need to put an image counter at the bottom of the page, that is, the access volume of the current page, the traffic data is saved in the txt fileAutomatically generate the num.txt file to customize the initial dataThe displayed digital image is saved in the img directory. you can replace it with your own exquisite image. You can replace it with another one. index. php isCall File, Very simple.

This program is only dozens of KB, and the system code design is easy to understand.

The effect is as follows:

The installation of the program is very simple:

1. This graphic counter does not require database support, as long as it can run PHP.Copy the php file in index. php to the desired webpage, And the other files will not move.

2. File structure:

(1), index. php, call counter File

<? Phpecho "you are the"; require ("count. php"); echo "guest";?>

(2) Core code of the count. php graphic counter

<? Php $ path = "img"; // The file clip of the image. img is saved in the corresponding folder $ f_name = "num.txt"; // the data of the counter is saved in num.txt $ n_digit = 10; // if the file does not exist, create a new file. The initial value is 100/if (! File_exists ($ f_name) {$ fp = fopen ($ f_name, "w"); fputs ($ fp, "100"); fclose ($ fp );} $ fp = fopen ($ f_name, "r"); // open the num.txt File $ hits = fgets ($ fp, $ n_digit); // start to calculate the data fclose ($ fp ); // close the file $ hits = (int) $ hits + 1; // increase the counter by 1 $ hits = (string) $ hits; $ fp = fopen ($ f_name, "w"); fputs ($ fp, $ hits); // write the new count fclose ($ fp ); // close the file // read the file cyclically and display the graphic counter for ($ I = 0; $ I <$ n_digit; $ I ++) $ hits = str_replace ("$ I", "

(3) num.txt: Save the Count File 

The traffic data is stored in the txt file, which can automatically generate the num.txt file and customize the initial data.

(4) img/save 0-9 graphics files

Download the source code and start your php image counter system learning journey!

TIPS: the system development is not complete yet, and there are still many deficiencies, but efforts will be made to improve it.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.