The code is as follows:
Header (' content-type:text/html; Charset=utf-8 ');
$online _log = "Count.dat"; Save the number of documents,
$timeout = 30;//30 sec No move author, think drop line
$entries = File ($online _log);
$temp = Array ();
for ($i =0; $i
$entry = Explode (",", Trim ($entries [$i]));
if ($entry [0]! = $_server["REMOTE_ADDR") && ($entry [1] > Time ())) {
Array_push ($temp, $entry [0]. ",". $entry [1]. " \ n "); Take out other visitors ' information and remove the timeout and save into $temp
}
}
Array_push ($temp, $_server["REMOTE_ADDR"]. ",". ( Time () + ($timeout)). " \ n "); Time to update visitors
$users _online = count ($temp); Calculate the number of people online
$entries = Implode ("", $temp);
Write file
$fp = fopen ($online _log, "w");
Flock ($FP, LOCK_EX); Flock () does not work correctly in NFS and some other network file systems
Fputs ($fp, $entries);
Flock ($FP, lock_un);
Fclose ($FP);
echo "Current Online". $users _online. " People ";
?>