小磊无痕博客

生命在于折腾

网站流量统




//AdminController.class.php
<?php

// +----------------------------------------------------------------------
// | name 流量统计插件后台管理
// +----------------------------------------------------------------------
// | Copyright (c) 2012-2014 https://www.abk0.com/, All rights reserved.
// +----------------------------------------------------------------------
// | Author: stone
// +----------------------------------------------------------------------

namespace Addon\Dyapp\Controller;

use Addons\Util\Adminaddonbase;

class AdminController extends Adminaddonbase {

    public function index() {
        //取得当天数据
        $time = date('y-m-d',time());
        $datasa = M("dyapp")->where("time='{$time}'")->find();
        $data["pv"] = $datasa["pv"];
        $data["ip"] = $datasa["ip"];
        $data["dip"] = $datasa["dip"];
        //取得昨天数据
         $times = time()- ( 1  *  24  *  60  *  60 );
         $datasav = M("dyapp")->where("time='{$times}'")->find();
        $data["spv"] = $datasav["pv"];
        $data["sip"] = $datasav["ip"];
        $data["sdip"] = $datasav["dip"];
        //取得最高纪录
        $datasaz = M("dyapp")->order('MAX(pv)')->find();
        $data["zpv"] = $datasaz["pv"];
        $data["time_zpv"] = $datasaz["time"];
        
        $datasaa = M("dyapp")->order('MAX(ip)')->find();
        $data["zip"] = $datasaa["ip"];
        $data["time_zip"] = $datasaa["time"];
        
        $datasab = M("dyapp")->order('MAX(dip)')->find();
        $data["zdip"] = $datasab["dip"];
        $data["time_zdip"] = $datasab["time"];

        $this->assign('data',$data);
        $this->display();
    }

}






<?php if (!defined('SHUIPF_VERSION')) exit(); ?>
<admintemplate file="Common/Head"/>
<body class="J_scroll_fixed">
<div class="wrap">
  <Admintemplate file="Common/Nav"/>

<style type="text/css">
<!--
tbody tr {
    height: 30px;
    border-top: 1px #dcdcdc solid;
    border-right: 1px #dcdcdc solid;
}
tbody tr td {
    border-right: 1px #dcdcdc solid;
    text-align: right;
    padding: 10px;
}
tbody tr td span {
    padding: 10px;
}
tbody .add {
    text-align: left;
}
-->
</style>  

<div style="border: 1px #dcdcdc solid;">
  <div style=" height: 30px; border-bottom: 1px #dcdcdc solid;background-color: #dcdcdc;color: #484848;line-height: 30px;"><h3 style="margin-left: 10px;">现在时间: <?php echo date("Y年m月d H:i:s",time());?></h3></div>
<table cellspacing='0' cellpadding='0'>
         <col width="200px" />
         <col/>
   <thead>
            <tr>
               <th></th>
               <th></th>
            </tr>
         </thead>
         <tbody>
            <tr><td>今天访问量(pv)</td><td class="add"><span>{$data.pv}</span></td></tr>
            <tr><td>今天ip访问量</td><td class="add"><span>{$data.ip}</span></td></tr>
            <tr><td>今天独立ip访问数</td><td class="add"><span>{$data.dip}</span></td></tr>
            <tr><td>昨天(pv)</td><td class="add"><span>{$data.spv}</span></td></tr>
            <tr><td>昨天(ip)</td><td class="add"><span>{$data.sip}</span></td></tr>
            <tr><td>历史最高(pv)</td><td><span>{$data.zpv}</span>[{$data.time_zpv}]</td></tr>
            <tr><td>历史最高(ip)</td><td><span>{$data.zip}</span>[{$data.time_zip}]</td></tr>
            <tr><td>历史最高独立用户访问</td><td><span>{$data.dip}</span>[{$data.time_zdip}]</td></tr>
        </tbody>
</table>
</div>  

</div>
<script src="{$config_siteurl}statics/js/common.js?v"></script>
</body>
</html>
//视图层index.php
<?php if (!defined('SHUIPF_VERSION')) exit(); ?>
<admintemplate file="Common/Head"/>
<body class="J_scroll_fixed">
<div class="wrap">
  <Admintemplate file="Common/Nav"/>

<style type="text/css">
<!--
tbody tr {
    height: 30px;
    border-top: 1px #dcdcdc solid;
    border-right: 1px #dcdcdc solid;
}
tbody tr td {
    border-right: 1px #dcdcdc solid;
    text-align: right;
    padding: 10px;
}
tbody tr td span {
    padding: 10px;
}
tbody .add {
    text-align: left;
}
-->
</style>  

<div style="border: 1px #dcdcdc solid;">
  <div style=" height: 30px; border-bottom: 1px #dcdcdc solid;background-color: #dcdcdc;color: #484848;line-height: 30px;"><h3 style="margin-left: 10px;">现在时间: <?php echo date("Y年m月d H:i:s",time());?></h3></div>
<table cellspacing='0' cellpadding='0'>
         <col width="200px" />
         <col/>
   <thead>
            <tr>
               <th></th>
               <th></th>
            </tr>
         </thead>
         <tbody>
            <tr><td>今天访问量(pv)</td><td class="add"><span>{$data.pv}</span></td></tr>
            <tr><td>今天ip访问量</td><td class="add"><span>{$data.ip}</span></td></tr>
            <tr><td>今天独立ip访问数</td><td class="add"><span>{$data.dip}</span></td></tr>
            <tr><td>昨天(pv)</td><td class="add"><span>{$data.spv}</span></td></tr>
            <tr><td>昨天(ip)</td><td class="add"><span>{$data.sip}</span></td></tr>
            <tr><td>历史最高(pv)</td><td><span>{$data.zpv}</span>[{$data.time_zpv}]</td></tr>
            <tr><td>历史最高(ip)</td><td><span>{$data.zip}</span>[{$data.time_zip}]</td></tr>
            <tr><td>历史最高独立用户访问</td><td><span>{$data.dip}</span>[{$data.time_zdip}]</td></tr>
        </tbody>
</table>
</div>  

</div>
<script src="{$config_siteurl}statics/js/common.js?v"></script>
</body>
</html>









//DyappAddon.class.php
<?php
/**
* +----------------------------------------------------------------------
* | name 流量统计插件 插件
* +----------------------------------------------------------------------
* | Copyright (c) 2012-2014 https://www.abk0.com/, All rights reserved.
* +----------------------------------------------------------------------
* | Author: alvye 
* +----------------------------------------------------------------------
 */

namespace Addon\Dyapp;

use \Addons\Util\Addon;

class DyappAddon extends Addon {

    //插件信息
    public $info = array(
        'name' => 'Dyapp',
        'title' => '访问统计',
        'description' => '记录访问者信息',
        'status' => 1,
        'author' => 'alvye',
        'version' => '1.0.1',
        'has_adminlist' => 1,
        'sign' => 'deyou',
    );

    //有开启插件后台情况下,添加对应的控制器方法
    //也就是插件目录下 Action/AdminController.class.php中,public属性的方法!
    //每个方法都是一个数组形式,删除,修改类需要具体参数的,建议隐藏!
    public $adminlist = array(
        array(
            //方法名称
            "action" => "",
            //附加参数 例如:a=12&id=777
            "data" => "",
            //类型,1:权限认证+菜单,0:只作为菜单
            "type" => 0,
            //状态,1是显示,0是不显示
            "status" => 1,
            //名称
            "name" => "",
            //备注
            "remark" => "",
            //排序
            "listorder" => 0,
        ),
    );

    //安装
    public function install() {

        //1、添加数据表
        $slq = $this->addonPath . 'dyapp.sql';
        $sql = file_get_contents($slq);
        $sql = $this->sqlSplit($sql, C("DB_PREFIX"));
        if (!empty($sql) && is_array($sql)) {
            foreach ($sql as $sql_split) {
                M()->execute($sql_split);
            }
        }
    
      return true;
    }

    //卸载
    public function uninstall() {
        $tablename = C("DB_PREFIX") . 'dyapp';
        M()->query("DROP TABLE $tablename");
        $tablename = C("DB_PREFIX") . 'dyapp_ip';
        M()->query("DROP TABLE $tablename");   
        return true;
    }

    /**
     * 分析处理sql语句,执行替换前缀都功能。
     * @param string $sql 原始的sql
     * @param string $tablepre 表前缀
     */
    private function sqlSplit($sql, $tablepre) {
        if ($tablepre != "lvyecms_")
            $sql = str_replace("lvyecms_", $tablepre, $sql);
        $sql = preg_replace("/TYPE=(InnoDB|MyISAM|MEMORY)( DEFAULT CHARSET=[^; ]+)?/", "ENGINE=\\1 DEFAULT CHARSET=utf8", $sql);
        if ($r_tablepre != $s_tablepre)
            $sql = str_replace($s_tablepre, $r_tablepre, $sql);
        $sql = str_replace("\r", "\n", $sql);
        $ret = array();
        $num = 0;
        $queriesarray = explode(";\n", trim($sql));
        unset($sql);
        foreach ($queriesarray as $query) {
            $ret[$num] = '';
            $queries = explode("\n", trim($query));
            $queries = array_filter($queries);
            foreach ($queries as $query) {
                $str1 = substr($query, 0, 1);
                if ($str1 != '#' && $str1 != '-')
                    $ret[$num] .= $query;
            }
            $num++;
        }
        return $ret;
    }
    
    //实现行为 app_init
    //$param 是行为传递过来的参数
    public function app_init($param = NULL) {
       //插件主要逻辑
       $time = date('y-m-d',time());
       $Dao = M("dyapp");
       $datasa = $Dao->where("time='{$time}'")->find();
       if(empty($datasa)){
          $data["time"] = $time;
          $id = $Dao->add($data);
       }else{
          $id = $datasa["id"];
       }
          $time = date('y-m-d',time());
           $ip = get_client_ip();
           $data = M("dyapp_ip")->where("ip='{$ip}'")->find();
         if(empty($data)){  //如果ip不存在
           $add["ip"] = $ip;
           $add["time"] = $time;
           $ta= D("dyapp_ip");
           $ta->create($add);
           $ta->add();
           $sip = M("dyapp")->where("id='{$id}'")->setInc("ip",1);  // 当天ip数 +1
        }else{
         $time_dip = time();
          $_time_dip = session('time_dip');
          if($time_dip <=$_time_dip){
           $sip = M("dyapp")->where("id='{$id}'")->setInc("dip",1); //独立ip +
          }else{
            session("time_dip",time()+86400); //隔一天
          }
        }
        $_time_pv = session('time_pv');
        if(!empty($time_pv)){
          $time_pv = time();
          if($_time_pv <= $time_pv){
            $sip = M("dyapp")->where("id='{$id}'")->setInc("pv",1); //pv +1
            session("time_pv",time()+900);  //1时(h)=3600秒(s) 30分(min)=1800秒(s) 15分(min)=900秒(s)
          }           
        }else{
          session("time_pv",time()+900);  //1时(h)=3600秒(s) 30分(min)=1800秒(s) 15分(min)=900秒(s)
        }
    }

}
//dyapp.sql
# Host: https://www.abk0.com
# Date: 2016-10-17 03:14:39
# author: alvye

#
# Structure for table "lvyecms_dyapp"
#

DROP TABLE IF EXISTS `lvyecms_dyapp`;
CREATE TABLE `lvyecms_dyapp` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `pv` int(11) DEFAULT '0' COMMENT '当天pv数',
  `ip` int(11) DEFAULT '0' COMMENT '当天ip数',
  `dip` int(11) DEFAULT '0' COMMENT '当天独立ip数',
  `time` varchar(50) DEFAULT NULL COMMENT '记录当天时间',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='访问记录';

#
# Structure for table "lvyecms_dyapp_data"
#

DROP TABLE IF EXISTS `lvyecms_dyapp_ip`;
CREATE TABLE `lvyecms_dyapp_ip` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ip` varchar(100) NOT NULL DEFAULT '' COMMENT 'ip库',
  `time` date DEFAULT NULL COMMENT '记录时间',
  PRIMARY KEY (`id`,`ip`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='ip库';






阅读更多
版权声明:欢迎转载 https://blog.csdn.net/xl13396198577/article/details/52837680
个人分类: php
想对作者说点什么? 我来说一句

网站流量

2007年02月09日 35KB 下载

搜索引擎营销:网站流量大提速

2011年11月20日 176.31MB 下载

网站流量分析报告 网站分析

2010年04月03日 3.39MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭