您现在的位置: 军旅同心 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 文章正文
基于数据库的在线人数,日访问量等统计
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:35:32
可以实现在线人数统计,日访问量统计,月访问量统计。。。。。

<?
$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>
欢迎来我的网站来灌水,有什么问题,给我留言。


 
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 管理登录 |