<?php/* @ PHP Online Population Statistics Program Copyright (c) by Pader 1:25 January 7, 2009 What is the use of It:note: the general independent online Statistics program is the number of IP numbers that are counted online, and this is not accurate such as LAN Visitors, such as companies, school rooms and internet cafes, although the network IP is different, but the external IP is the same if the same LAN, no matter how many people visit your site is only considered a person this small program solves this problem, it is computer-based, each computer is counted as a visitor Of course, because of the use of cookies, if you use two different core browser access on the same computer, then don't be conceivable. */$filename = ' online.txt '; Data file, if no new $cookiename = ' vgotcn_onlinecount '; Cookie name $onlinetime = 600; Online effective time, in seconds (i.e. 600 equals 10 minutes) @ $online = file ($filename); Data file, if no new $nowtime = time (); $nowonline = Array (); /* Get still valid data */if (!empty ($online)) {foreach ($online as $line) {$row = explode (' | ', $line); $sesstime = Trim ($row [1]); F (($nowtime-$sesstime) <= $onlinetime) {//If the data continues to persist within the time of validity, otherwise it will not be counted $nowonline [$row [0]] = $sesstime;//Get online list to array , the session ID is the key name, the last communication time is the key value}}}//@ Create a Visitor communication state using cookie communication cookie will expire when the browser is closed, but if you do not close the browser, this cookie will remain in effect until the online time of the program setting expires */if (Isset ($_ cookie[$cookiename])) {//If there is a cookie that is not first accessed then do not add the number of people and update the communication time $uid = $_cookie[$cookiename];} else {//If no cookie is the first access $vid = 0 ; Initialize Visitor ID do {//Give the user a new ID $vid + +; $uid = ' U '. $vid; } while (Array_key_exists ($uid, $nowonline)); Setcookie ($cookiename, $uid); } $nowonline [$uid] = $nowtime; Update current time status//@ Stats now online number */$total _online = count ($nowonline); /* Write Data */if ($fp = @fopen ($filename, ' W ')) {if (Flock ($FP, lock_ex)) {rewind ($fp); foreach ($nowonline as $fuid + = $ft IME) {$fline = $fuid. ' | '. $ftime. " \ n "; @fputs ($fp, $fline); } flock ($FP, lock_un); Fclose ($FP);