欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-06-09 16:06:01
可以实现在线人数统计,日访问量统计,月访问量统计。。。。。
可以实现在线人数统计,日访问量统计,月访问量统计。。。。。

<?
$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");
<head>
<meta http-equiv="refresh" content=<? echo $duration?>; url=<? echo $php_self; ?>">
</head>
欢迎来我的网站来灌水,有什么问题,给我留言。