<?php
$ipaddr = $_SERVER['REMOTE_ADDR'];
$now = time();
$out = time() + 600;

$result = mysql_query("SELECT * from xcounter");
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_array($result);

$Sql5 = mysql_query("delete from xip where time_out <= '$out'");

if ($num_rows == 0)
{
$Sql = mysql_query("INSERT INTO xcounter (today,thismonth,thisyear,dateline,total) VALUES (1,1,1,$now,1)");
$Sql2 = mysql_query("INSERT INTO xip (time_in,userip,time_out) VALUES ($now,'$ipaddr',$out)");
}else{
$num_rowsxx = mysql_num_rows(mysql_query("SELECT * from xip"));
if($num_rowsxx == 0)
{
$Sql3 = mysql_query("INSERT INTO xip (time_in,userip,time_out) VALUES ($now,'$ipaddr',$out)");
}

//$num_ipx = mysql_num_rows(mysql_query("SELECT * from xip where userip='$ipaddr'"));
//if($num_ipx==0){
$Sql65 = mysql_query("UPDATE xcounter SET today=today+1,thismonth=thismonth+1,thisyear=thisyear+1,total=total+1");
//}
}

if ( (date("d",$row['dateline'])) <>  (date("d",$now)) )
{
$Sql = mysql_query("UPDATE xcounter SET today=1,dateline=$now");
}
if ( (date("m",$row['dateline'])) <>  (date("m",$now)) )
{
$Sql = mysql_query("UPDATE xcounter SET today=1,thismonth=1,dateline=$now");
}

if ( (date("Y",$row['dateline'])) <  (date("Y",$now)) )
{
$Sql = mysql_query("UPDATE xcounter SET today=1,thismonth=1,thisyear=1,dateline=$now");
}
?>