Simple counter implementation

Source: Internet
Author: User
Note: The implementation principle is to use PHP functions to read the data of text files, so as to achieve data statistics. 1. create a new file named counter. php. The code is as follows :? Phpselect counter.txt.pdf file counter_file(counter.txt); open the text file $ visitsfile ($ counter_file); automatically add 1 counter



Note:
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 );
// Automatically add 1
$ Visits [0];
// This click is automatically recorded
$ Fp = fopen ($ counter_file, "w ");
// Write it into the counter.txt file and record it
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. change the permission to 777.

A simple counter is implemented.

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.