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.