Php simply calculates the number of online users, and php calculates the number of online users. Php is a simple way to count the number of online users. php is used to count the number of online users. For your reference, the details are as follows: first, you can use php to calculate the number of online users.
This example describes how php calculates the number of online users. We will share this with you for your reference. The details are as follows:
<? Php // first, you must have the permission to read and write files. // this program can be run directly. The first error is reported? $ Online_log = "count. dat "; // the file that saves the number of people, $ timeout = 30; // The author is not moved within 30 seconds. the file is considered to be offline $ entries = file ($ online_log ); $ temp = array (); for ($ I = 0; $ I
Time () {array_push ($ temp, $ entry [0]. ",". $ entry [1]. "\ n"); // retrieve the information of other viewers, remove the timeout, and save it to $ temp} array_push ($ temp, getenv ('remote _ ADDR '). ",". (time () + ($ timeout )). "\ n"); // update the viewer's time $ users_online = count ($ temp); // calculate the number of online users $ entries = implode ("", $ temp ); // write the file $ fp = fopen ($ online_log, "w"); flock ($ fp, LOCK_EX); // flock () fputs ($ fp, $ entries), flock ($ fp, LOCK_UN), and fclose ($ fp) cannot work normally in NFS and other network file systems ); echo "existing ". $ users_onli Ne. "people online";?>
Usage:
Save the preceding code as count. php. where to use it:
include("count.php");