Simple counter implementation

Source: Internet
Author: User
This tutorial is of the original load. for details, refer to the webpage tutorial. the implementation principle is to use the function of PHP to read data from text files, so as to achieve data statistics. 1. create a new file named counter. php. The code is as follows: This tutorial is of the original load. For more information, see The Webpage Tutorial.

Clarification:
The principle is to use PHP functions to read data from text files, so as to achieve data statistics.

1. create a new file named counter. php. The code is as follows:

// Select the counter.txt text file
$ Counter_file = ('counter.txt ');
// Open a text file
$ Visits = file ($ counter_file );
// Actively add 1
$ Visits [0];
// Active record of this click
$ Fp = fopen ($ counter_file, 'w ');
// Enter the counter.txt file to record
Fputs ($ fp, '$ visits [0]');
// Close the file
Fclose ($ fp );
// Display Times
Echo $ visits [0];
?>

2. Place the following code in the place where you want to display the number of clicks to display the file.

Include ('counter. php ');
?>

3. create a new counter.txt file at the end. The permission is changed to 777.

A simple counter is implemented.
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.