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

5年以前  |  阅读数:311 次  |  编程语言:PHP 

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

<?
$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");

; url="> 欢迎来我的网站来灌水,有什么问题,给我留言。
 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例