Php enables the current number of online users. Principle: calculate the number of online users based on different IP addresses. Implementation Method: you can use a database or text. Here I use text implementation .? Php *** @ Date2010.04.07 principle: calculate the number of online users based on different IP addresses.
Implementation Method: you can use a database or text.
Here I use text implementation.
/**
* @ Date 2010.04.07
* @ Author Huaxia star bkJia.com
* @ Blog http://hi.baidu.com/woaidelphi/blog
*/
$ User_online = "count. php"; // The number of objects that are stored
Touch ($ user_online); // If this file is not available, create
$ Timeout = 30; // The author is not moved within 30 seconds.
$ User_arr = file_get_contents ($ user_online );
$ User_arr = explode (#, rtrim ($ user_arr, #); print_r ($ user_arr );
$ Temp = array ();
Foreach ($ user_arr as $ value ){
$ User = explode (",", trim ($ value ));
If ($ user [0]! = Getenv (REMOTE_ADDR) & ($ user [1]> time () {// if it is not the current user's IP address and does not time out, it will be placed in the array
Array_push ($ temp, $ user [0]. ",". $ user [1]);
}
}
Array_push ($ temp, getenv (REMOTE_ADDR). ",". (time () + ($ timeout). #); // save user information
$ User_arr = implode ("#", $ temp );
// Write a file
$ Fp = fopen ($ user_online, "w ");
Flock ($ fp, LOCK_EX); // flock () cannot work normally in NFS or some other network file systems
Fputs ($ fp, $ user_arr );
Flock ($ fp, LOCK_UN );
Fclose ($ fp );
Echo "currently". count ($ temp). "online ";
?>
Bytes. Implementation Method: you can use a database or text. Here I use text implementation. ? Php/*** @ Date 2010.04.07...