$scr[0] = "counter.ip";
$scr[1] = "counter.dat";
$scr[2] = "counter.inf";
$aktu_ip = $REMOTE_ADDR;
$host = gethostbyaddr($aktu_ip);
$aktu_czas = (date('G') * 3600) + (date('i') * 60) + date('s'); // date(G) * 60 + date(i);
$czas_online = 600; // sekund (10 minut)
$czas_opuznienia = 900; // sekund (15 minut)
$data = date("Y-m-d", time());
$online = 1;
$zmienna = False;
$nowe_dane = '';
function open($name = "", $trybe = "r", $value = "0")
{
if (file_exists($name))
{
$file = fopen($name, $trybe);
flock($file, 1);
if (filesize($name) > 0) return fread(fopen($name, $trybe), filesize($name)); else return $value;
flock($file, 3);
fclose($file);
}
}
function save($name = "", $date = "", $trybe = "w")
{
if (file_exists($name))
{
$file = fopen($name, $trybe);
flock($file, 2);
fwrite($file, $date);
flock($file, 3);
fclose($file);
}
}
$dane = explode(chr(1), open($scr[1]));
if (!strcmp($dane[2], $data))
{
$tab1 = explode(chr(1), open($scr[0]));
for ($x = 0; $x <= count($tab1) - 2; $x += 2)
{
if (!strcmp($aktu_ip, $tab1[$x]))
{
if ($aktu_czas - $czas_opuznienia < $tab1[$x + 1]) $zmienna = True;
}
else
{
if ($aktu_czas - $czas_opuznienia < $tab1[$x + 1])
{
$nowe_dane .= $tab1[$x].chr(1).$tab1[$x + 1].chr(1);
if ($aktu_czas - $czas_online < $tab1[$x + 1]) $online++;
}
}
}
if ($zmienna == 0)
{
$dane[0]++;
$dane[1]++;
save($scr[1], $dane[0].chr(1).$dane[1].chr(1).$dane[2]);
$wszystko = $dane[0].chr(1).$dane[1].chr(1).$online.chr(1).date("Y-m-d".chr(1)."G:i:s", time()).chr(1).$aktu_ip.chr(1).$host.chr(1).$HTTP_REFERER.chr(1).$HTTP_USER_AGENT.chr(13).chr(10);
save($scr[2], $wszystko, "a");
}
}
else
{
save($scr[0]);
$dane[0]++;
$dane[1] = 1;
save($scr[1], $dane[0].chr(1).$dane[1].chr(1).$data);
$wszystko = $dane[0].chr(1).$dane[1].chr(1).$online.chr(1).date("Y-m-d".chr(1)."G:i:s", time()).chr(1).$aktu_ip.chr(1).$host.chr(1).$HTTP_REFERER.chr(1).$HTTP_USER_AGENT.chr(13).chr(10);
save($scr[2], $wszystko,"a");
}
$nowe_dane .= $aktu_ip.chr(1).$aktu_czas.chr(1);
save($scr[0], $nowe_dane);
?>