PHP Graphics Counter program displays site user views _php instances

Source: Internet
Author: User
PHP Graphics Counter Program is a simple picture counter, in order to visually show how many users browse a site, you need to put a picture counter at the bottom of the page, that is, the current page access, data is stored in the TXT file, you can automatic generation of num.txt files, custom initial data, the display of digital pictures saved in the IMG directory, can be replaced by their own beautiful pictures, replacement can be, index.php is Call FileVery simple.

This program is only dozens of KB, the system code design is simple and understandable.

The effect is as follows:

The installation of the program is simple:

1, this graphics counter does not need the support of the database, as long as the PHP can be run , the PHP files in the index.php to the required pages can be, other files do not move.

2, the structure of the file:

(1), index.php, call counter file

<?phpecho "You are the first"; Require ("count.php"); echo "Bit visitor";?>

(2), the core code of the count.php graphics counter

<?php $path = "img";//the folder in which the picture is located, IMG is under the corresponding folder $f _name = "num.txt";//Counter data is saved in num.txt $n _digit = 10; If the file does not exist, create a new file with an initial value of 100/if (!file_exists ($f _name)) {$fp =fopen ($f _name, "W"), Fputs ($fp, "+"), fclose ($FP);} $fp = fopen ($f _name, "R"); Open num.txt file $hits =fgets ($fp, $n _digit); Start taking Data fclose ($FP); Close file $hits = (int) $hits + 1;//counter increases by 1 $hits = (string) $hits;  $FP =fopen ($f _name, "w"); Fputs ($fp, $hits);//write a new Count fclose ($FP); Close File//loop Read and display graphics counter for ($i =0; $i < $n _digit; $i + +)  $hits = Str_replace ("$i", "", "$hits"); Echo $hits;  >

(3) Num.txt save count file

The data of the traffic is saved in TXT file, can generate Num.txt file automatically, customize the initial data

(4) img/Save 0-9 graphics file

Download the source code, start your PHP picture counter system learning journey now!

Tip: This system development is not perfect, there are many deficiencies, but will continue to improve.

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support the script home.

  • Related Article

    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.