Php does not require database visitor counters (saving data in txt text)-PHP source code

Source: Internet
Author: User
This program uses php + txt to calculate the number of web page visits. It is simple and practical to record the number of times a user accesses a Web page. This program uses php + txt to calculate the number of web page visits. It is simple and practical to record the number of times a user accesses a Web page.

Script ec (2); script


Include ("counter. php ")
?>

The Code is as follows:


Visitor counter




You are the first Visitors,
Your ip Address:


The Code is as follows:

$ Fp = fopen ("counter.txt", "r + ");
$ Counter = fgets ($ fp, 80 );
$ Counter = doubleval ($ counter) + 1;
Fseek ($ fp, 0 );
Fputs ($ fp, $ counter );
Fclose ($ fp );

/*
If you want to make this statistician an image, you can add the following code and make the image named in the images directory.
*/
$ Number = strlen ("$ counter ");
For ($ I = 0; $ I <$ number; $ I ++ ){
$ Gra_counter = substr ($ counter, $ I, 1 );
$ Image = $ image ."";

}


If ($ http_server_vars ["http_x_forwarded_for"])
{
$ Ip = $ http_server_vars ["http_x_forwarded_for"];
}
Elseif ($ http_server_vars ["http_client_ip"])
{
$ Ip = $ http_server_vars ["http_client_ip"];
}
Elseif ($ http_server_vars ["remote_addr"])
{
$ Ip = $ http_server_vars ["remote_addr"];
}
Elseif (getenv ("http_x_forwarded_for "))
{
$ Ip = getenv ("http_x_forwarded_for ");
}
Elseif (getenv ("http_client_ip "))
{
$ Ip = getenv ("http_client_ip ");
}
Elseif (getenv ("remote_addr "))
{
$ Ip = getenv ("remote_addr ");
}
Else
{
$ Ip = "unknown ";
}

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.