/ Published in: PHP

Count how many users are connected to a site (execute this function in every page, put it in the header).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getIP() { $ip=""; else $ip = ""; return $ip; } function howManyIps() { $filename = "./howmanyip.log"; $seconds = 300; $yourIP = getIP(); $count = 0; //lock the file //read data ips //if file is locked get out $s = ""; $already=false; //update data and search user ip //update your user timer if ($yourIP==$arData[0]) { $already=true; } // check if user is old $s.=$arData[0]." ".$arData[1]."\n"; $count++; } } if (!$already) { //your user is new, add it to the list $count++; } //save the list //remove thr lock return $count; }
URL: http://www.barattalo.it/2009/12/03/how-many-users-are-connected/
Comments
