基於數據庫的在線人數,日訪問量等統計

可以實現在線人數統計,日訪問量統計,月訪問量統計。。。。。
<?
$sql = "CREATE TABLE guestinfo(id integer DEFAULT 0 NOT NULL AUTO_INCREMENT,
ipaddress varchar(20),
host varchar(20),
cometime datetime,
refreshtime datetime,
leavetime datetime,
PRIMARY KEY(id),
UNIQUE id(id),
index guestinfo(id)
)";
mysql_query($sql, $connect);
?>
<?
$duration = 300;
$sql = "select * from guestinfo where (leavetime is null or leavetime=) and ( UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(refreshtime))>$duration";
$result=@mysql_query($sql);
while($row=@mysql_fetch_array($result))
{
$id = $row[id];
$sql = "update guestinfo set leavetime=now() where id=$id";
mysql_query($sql);
}
$sql = "select * from guestinfo where ipaddress=$REMOTE_ADDR and (leavetime is null or leavetime=)";

$result = @mysql_query($sql);
if($row=@mysql_fetch_array($result))
{
$id = $row[id];
$sql="update guestinfo set refreshtime=now() where id=$id";
mysql_query($sql);
}
else
{
$sql = "insert into guestinfo(ipaddress,host,cometime,refreshtime)
values($REMOTE_ADDR,$REMOTE_HOST,now(),now())";
mysql_query($sql);
}
$date= mktime(0,0,0,date("m"),date("d"),date("Y"));
$sql = "select count(*) from guestinfo where UNIX_TIMESTAMP(refreshtime)> $date";
$result = mysql_query($sql);
if($result)
{
$row = mysql_fetch_array($result);
$todayaccess = $row["count(*)"];
}
else $todayaccess = 0;
$sql = "select count(*) from guestinfo where leavetime is null or leavetime=";
$result = mysql_query($sql);
if($result)
{
$row = mysql_fetch_array($result);
$nowonline= $row["count(*)"];
}
else $nowonline = 0;
mysql_close($connect);
?>
include("guest.php");

<meta http-equiv="Refresh" content=; url=">

歡迎來我的網站來灌水,有什麼問題,給我留言。

發佈留言