You can use sessions for the tracking and have a timelimit to purge those which have not re-loaded a page in more than a certain number of seconds.
<?php
//read in all in one go because it will be quicker and even if you have a couple of
//thousand people online at once the file will not get too huge
$contents=file($file);
$found=true;
for($i=0;$i<count($contents);$i++) {
//two, comma seperated values. uniqueid and time last accessed
$parts=explode(',',$contents[$i]);
if($_SESSION['uniqueid']==$parts[0]) {
$parts[1]=time();
$found=true;
}
//remove from contents array if too old
if($parts[1]<time()-900) {
array_splice($contents,$i,1);
--$i;
}
}
//If the user isn't found in the file
if(!$found) {
$uniqueid=md5(uniqid(rand(), true));
$time=time();
$contents[]=$uniqueid.','.$time;
$_SESSION['uniqueid']=$uniqueid;
}
$contents=implode("\n",$contents);
//write contents back to file
//put them all back in the file
I haven't tested this at all, it's off the top of my head and straight down here so there'll probably be a few errors in there and it's probably the best way of doing it but it get's the gist accross.
Good Luck
Bubble