<?
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();
$cutoff = 15; //online cut of time
$exists = 0;
$users = 0;
$user = "";
$fp = fopen ("online.txt","r+"); //if the file exists open it
while (!feof($fp))
{
$user[] = chop(fgets($fp,65536));
}
fseek($fp,0,SEEK_SET);
foreach ($user as $line)
{
list($oldip,$oldtime) = explode('|',$line);
if ($oldip == $ip) {$oldtime = $time;$exists = 1;}
if ($time < $oldtime + ($cutoff * 60))
{
fputs($fp,"$oldip|$oldtime\n");
$users = $users + 1;
}
}
if ($exists == 0)
{
fputs($fp,"$ip|$time\n");
$users = $users + 1;
}
fclose ($fp);
$countfile = "count.dat";
$ipcounter = "today.dat";
$countdate = date("j-n-Y");
$visitorip = $_SERVER[REMOTE_ADDR];
$maxrecord = date("d.m.Y (H:i)");
if (!file_exists($ipcounter)) { $fp = fopen($ipcounter, 'w+'); }
if (!file_exists($countfile)) { $fp = fopen($countfile, 'w+'); fwrite($fp, "0|0|0|1|$countdate|0|$maxrecord"); }
$fcontents = file_get_contents($countfile);
list($today, $yesterday, $total, $days, $nowdate, $max, $nowrecord) = explode("|", $fcontents);
if($countdate != $nowdate) {
$ipfile2 = fopen($ipcounter, 'w');
$line = "$visitorip\n";
fwrite($ipfile2, $line, strlen($line));
fclose($ipfile2);
if($today > $max) { $max = $today; $nowrecord = $maxrecord; }
$yesterday = $today;
$today = 1;
$total++;
$days++;
$fp = fopen($countfile, 'w');
fwrite($fp, "1|$yesterday|$total|$days|$countdate|$max|$nowrecord");
fclose($fp);
}
else {
$ipfile = fopen($ipcounter, 'rb');
$line = array();
while (!feof($ipfile)) $line[]=fgets($ipfile,1024);
for ($i=0; $i<(count($line)); $i++) {
list($visitorip_x) = split("\n",$line[$i]);
if ($visitorip == $visitorip_x) {$found = 1;}
}
fclose($ipfile);
if (!$found) {
$ipfile2 = fopen($ipcounter, 'ab');
$line = "$visitorip\n";
fwrite($ipfile2, $line, strlen($line));
fclose($ipfile2);
$today++;
$total++;
if($today > $max) { $max = $today; $nowrecord = $maxrecord; }
$fp = fopen($countfile, 'r+');
fwrite($fp, "$today|$yesterday|$total|$days|$countdate|$max|$nowrecord");
fclose($fp);
}
}
if($days == 1) { $dendni = "ден"; }
else { $dendni = "дни"; }
$sredno="ceil($total/$days)";
print 'document.write("На линия: <B>'.$users.'</B><br>
Уникални Днес <b> '.$today.'</b> <br>
Уникални Вчера <b> '.$yesterday.'</b><br>
Уникални Общо <b> '.$total.'</b> за <b>'.$days.'</b> '.$dendni.' <br>
Рекорд Уникални<b> '.$max.'</b>");';
?>