PHP graphic counter program to display website user views _ php instance

Source: Internet
Author: User
This article mainly shares with you the PHP graphic counter program, which intuitively shows the page views of website users. if you are interested, you can refer to the PHP graphic counter program as a simple image counter, in order to intuitively display the number of users browsing a website, you need to put an image counter at the bottom of the page, that is, the current page access Volume. the access volume data is saved in the txt file. Automatically 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 is Call 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", "", "$ hits"); echo $ hits;?>

(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 to everyone's learning, and I hope you can support your own home.

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.