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"";
?>