This article is an example of PHP simple statistics online number of methods. Share to everyone for your reference, as follows:
<?php//first you have to read and write the permissions of the file//This program can be run directly, the first error, to fou smear shoot? $online _log = "Count.dat"; Save the number of files, $timeout = 30;//30 seconds not moving the author, think the drop line $entries = file ($online _log); $temp = Array (); for ($i =0; $i time
()) { Array_push ($temp, $entry [0]. ",". $entry [1]. " \ n "); Remove the information from other visitors and remove the timeout, and save it in $temp}}array_push ($temp, getenv (' remote_addr '). ",". ( Time () + ($timeout)). " \ n "); Update the browser time $users_online = count ($temp); Calculate the number of online $entries = Implode ("", $temp);//write File $fp = fopen ($online _log, "w"); Flock ($fp, LOCK_EX); Flock () cannot work properly in NFS and some other network file systems Fputs ($FP, $entries), Flock ($FP, Lock_un), fclose ($FP), echo "current". $users _online. " People online ";? >
How to use:
Save the above code as count.php, in the location you want to use:
Include ("count.php");
More about PHP related content readers can view the topic: "PHP File Operation Summary", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document tips summary (including word, excel,access,ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"
I hope this article is helpful to you in PHP programming.
The above describes the PHP simple statistics on the number of online methods, including PHP, the content of the method, I hope that the PHP tutorial interested in a friend helpful.