w którymś z postów coś takiego widziałem:
<?php
class onlineInfo
{
private $maxLastSeenTime=240;
private $userOnList=false;
public function __construct()
{
self::$dataFile=self::$dir.'/temp/usersOnline.tmp';
{
$this->save();
}
$this->userIp=$_SERVER['REMOTE_ADDR'];
$this->load();
$this->checkVisitors();
$this->save();
}
private function load()
{
$this->data=file(self::$dataFile); $count=count($this->data); if($count>0)
{
for($i=0;$i<$count;++$i)
{
$this->data[$i]=trim($this->data[$i]); $this->userInfo[$i]=explode("|", $this->data[$i]); if($this->userInfo[$i][0]==$this->userIp)
{
$this->userOnList=true;
$this->lastAvtivityTime=$this->userInfo[$i][0];
}
}
}
if(!$this->userOnList)
{
$this->userInfo[$count][0]=$this->userIp;
$this->userInfo[$count][1
]=time(); }
}
function checkVisitors()
{
$count=count($this->userInfo); if($count>0)
{
for($i=0;$i<$count;++$i)
{
if($this->maxLastSeenTime<=($currentTime-$this->userInfo[$i][1]))
{
if($this->userInfo[$i][0]==$this->userIp)
{
$this->userInfo[$i][1
]=time(); continue;
}
unset($this->userInfo[$i]); }
else
{
if($this->userInfo[$i][0]==$this->userIp)
{
$this->userInfo[$i][1
]=time(); }
}
}
}
}
public function getVisitors()
{
return count($this->userInfo); }
function save()
{
$string='';
$count=count($this->userInfo);
$this->saveArray=array(); $this->userInfo=array_merge($this->saveArray, $this->userInfo);
$lineEnd="\n";
if($count>0)
{
for($i=0;$i<$count;++$i)
{
if($i==$count-1)
{
$lineEnd='';
}
{
$string.=implode("|", $this->userInfo[$i]).$lineEnd; }
}
}
file_put_contents(self::$dataFile, $string);
}
}
$oInfo = new onlineInfo();
print 'ilo�c os�b online: '.$oInfo->getVisitors();
?>
może się przyda, pozdr