基于数据库的在线人数,日访问量等统计

时间:2021-05-18

可以实现在线人数统计,日访问量统计,月访问量统计。。。。。

<?
$sql = "CREATE TABLE guestinfo(id integer DEFAULT '0' NOT NULLAUTO_INCREMENT,
ipaddress varchar(20),
hostvarchar(20),
cometimedatetime,
refreshtime datetime,
leavetimedatetime,
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 whereUNIX_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 whereleavetime 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");
<head>
<meta http-equiv="Refresh" content=<? echo $duration?>; url=<? echo $PHP_SELF; ?>">
</head>
欢迎来我的网站来灌水,有什么问题,给我留言。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章