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

Zarah ·
更新时间:2024-11-14
· 749 次阅读

可以实现在线人数统计,日访问量统计,月访问量统计。。。。。
<?
$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(*)"];
    }
  &n bsp; 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");
<head>
<meta http-equiv="Refresh" content=<? echo $duration?>; url=<? echo $PHP_SELF; ?>">
</head>
欢迎来我的网站来灌水,有什么问题,给我留言。
您可能感兴趣的文章:ASP Access实现网站计数器(访问量)asp.net 实现静态页面累加访问量的三种方式asp统计信息实现代码/文章每日、每周、每月、总访问量的方法JS 精确统计网站访问量的实例代码ASP.net中网站访问量统计方法代码linux下统计appche站点IP访问量的shell脚本mysql优化连接数防止访问量过高的方法JavaScript实现网站访问次数统计代码



数据 访问量 数据库

需要 登录 后方可回复, 如果你还没有账号请 注册新账号