Statistics | online | number online
This method does not need the MySQL database support, uses the ordinary text to realize the counting function
First, you have permission to read and write files.
This procedure can be run directly, the first error, to Fou painted tip?
$online _log = "Count.dat"; Save the number of documents,
$timeout = 30;//30 in seconds without moving the author, who thinks that the drop line
$entries = File ($online _log);
$temp = Array ();
for ($i =0; $i
$entry = Explode (",", Trim ($entries [$i]));
if ($entry [0]!= getenv (' remote_addr ')) && ($entry [1] > Time ())) {
Array_push ($temp, $entry [0]. ",". $entry [1]. " \ n "); Remove the other viewer's information and remove the timeout and save it in $temp
}
}
Array_push ($temp, getenv (' remote_addr '). ",". ( Time () + ($timeout)). " \ n "); Update the viewer's time
$users _online = count ($temp); Calculate online numbers
$entries = Implode ("", $temp);
Write to File
$fp = fopen ($online _log, "w");
Flock ($FP, LOCK_EX); Flock () does not work in NFS and some other network file systems
Fputs ($fp, $entries);
Flock ($FP, lock_un);
Fclose ($FP);
echo "currently has". $users _online. " People online ";
?>
How to use:
1. Save the above code as count.php
2. In the required page to introduce counters can be