<?php
// start online
$tttime = time();
$xxtime = time()+3600;

$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
$sql = "select Time from online where IP='$REMOTE_ADDR'";
$result = mysql_query($sql);
if (mysql_num_rows($result)==0){
$result = mysql_query("insert into online SET IP='$REMOTE_ADDR', Time='$xxtime'");
}else{
$result = mysql_query("update online set Time='$xxtime' where ip='$REMOTE_ADDR'");
}

$sqld = mysql_query("delete from online where Time < '$tttime'");

$OnlineUsers = mysql_query("select * from online");
$online = mysql_num_rows($OnlineUsers);
// end online


// start counter
$tttimec = time();
$xxtimec = time()+600;

$sqlcounter = @mysql_query("select Time from ips where userip='$REMOTE_ADDR'");
if (mysql_num_rows($sqlcounter)==0){
$sql = @mysql_query("insert into ips SET userip='$REMOTE_ADDR', Time='$tttimec'");
$Sql = @mysql_query("UPDATE counter SET total=total+1") or die("error");
}else{
$sql = @mysql_query("update ips set Time='$tttimec' where userip='$REMOTE_ADDR'");
}

$sql = @mysql_query("delete from ips where Time > '$xxtimec'");
$sql2 = @mysql_query("SELECT * from counter") or die("error");
$row2 = mysql_fetch_array($sql2);
$total = $row2['total'] ;
// end counter


//refere start
$ipp = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
$ref = addslashes($ref);

$links = $ref;
$links = parse_url($links);
$llinkk = $links[host];

$num = mysql_query("select * from stats where refere='$ref'");
$refnumber = mysql_num_rows($num);

if($refnumber == 0){

if($_SERVER['SERVER_NAME'] != $llinkk AND $ref != ""){
$sqlr = mysql_query("insert into stats SET ip='$ipp', refere='$ref', date='".time()."', counter='1'");
}

}else{
$updater = mysql_query("update stats set counter=counter+1, date='".time()."', ip='$ipp' where refere='$ref'");
}
//end refere


// start xcounter
$result = mysql_query("SELECT * from xcounter");
$row = mysql_fetch_array($result);
$Htoday = $row['today'] ;
$Hmonth = $row['thismonth'] ;
$Hyear  = $row['thisyear'] ;
$Htotal = $row['total'] ;
// end xcounter
?>