Php statistician code (source code of online statistics program)-PHP source code

Source: Internet
Author: User
This kind of code can count the number of online users on your website. It is supported by php + txt without data. This kind of code can count the number of online users on your website. It is supported by php + txt without data.

Script ec (2); script

$ Time = gettimeofday (void );

// File initialization start
If (@ filesize ("time. text") <= 0 ){

$ Fd_time = fopen ("time. text", "w + ");
Fputs ($ fd_time, $ time [sec]);
Fclose ($ fd_time );

$ Fd_time = fopen ("ip. text", "w + ");
Fclose ($ fd_time );

}
// File initialization over


// Update time start
$ Tamp = file ("time. text ");
$ Equal = ($ time [sec]-$ tamp [0]);
If ($ equal> 60 ){

$ Fd_time = fopen ("time. text", "w + ");
Fputs ($ fd_time ,"");
Fclose ($ fd_time );

}
// Update time over


// Check ip start
$ Fd_ip = fopen ("ip. text", "a + ");

// Obtain the user IP Address
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 ";
}


$ Ip_adds = file ("ip. text ");
For ($ I; $ I

If ($ ip. "" ==$ ip_adds [$ I]) {
$ Ip_check = 1;
Break;
}
}

If ($ ip_check! = 1 ){
Fputs ($ fd_ip, $ ip ."");
}
Fclose ($ fd_ip );
// Check ip over


$ Ip_adds = count (file ("ip. text "));

?>
Call Method

/*
* Title: simple online user count statistics
*
* Author: Deng Dongdong
*
* Created on: 09:42:31
*
* Technical support: php100 learning and communication 22: 108610071
**/
?>
Include ("online. php ");
$ Fd_ip = file ("ip. text ");
?>
Online users

Total online users of the php100 Forum: 08610071 people

User ip Address:

Echo"";For ($ I = 0; $ I <count ($ ip_adds); $ I ++ ){Echo"". Substr ($ fd_ip [$ I], 0,0-strlen (strrchr ($ fd_ip [$ I], '.').". *";}Echo"";

?>

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.