PHP implements website traffic counters and php traffic counters

Source: Internet
Author: User

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.

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.