PHP implements website traffic counters and php traffic counters
Simple website traffic counters are implemented as follows:
DescriptionIdeas:
1. the user sends an access request to the server
2. The server reads the access count file, + 1, and returns it to the client
3. The server saves new browsing times
4. Access new users by repeating 123.
Solution(Main algorithms ):
1. Data File: counter. dat
2. Read data files
Open the file;
If it does not exist, create it and use 0 as the first recognized data;
Otherwise, read the data;
Close the file.
3. Write the accumulated data to the file counter. dat.
Accumulate data;
Open the file;
Write data;
Close the file;
4. output information to the webpage;
Create the Count_Visitor folder.
In the Count_Visitor folder, create the Count_Visitor.php file and type the following code:
<Html>
If necessary, you can type the css file decoration.
Variables in the Code and their meanings
$ Max_len: Custom variable. The maximum number of digits of the counter;
$ CounterFile: Custom variable. Files stored by the counter (path and file name );
$ Counter: Custom variable. The counter value;
$ Cf: Custom variable. Open the counter file handle;
Functions and meanings contained in the Code
File_exists ($ CounterFile): determines whether the file exists;
Fopen ($ CounterFile, "w"): Open the file in writing mode. (The function has its own attributes. If this attribute does not exist, it is created)
Fopen ($ CounterFile, 'R'): open a file in read-only mode.
Fgets ($ cf, $ max_len): reads characters of the specified length from a file.
Fputs ($ cf, "0"): writes the character "0" to $ cf
Fclose ($ cf): Close the files opened by $ cf
Trim (fgets ($ cf, $ max_len): removes the space characters on both sides of the string.
Today's note is here!
Simple php small application.
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.