业务经理

微信扫描以上二维码

028-61286886

技术咨询

页面默认的阅读数,怎么不限制ip增加阅读计数

迅睿框架 更新 2020-06-23 18:03:05 龙媒

页面默认的阅读数,是根据ip来判断的,一个ip只能计算一次,请问怎么把这个限制取消?就是不限制ip增加阅读计数。

方案

  • 迅睿框架创始人 #1 · 2020-06-22 16:08:33
    不能取消限制,但是你可以把控制器复制出来,重新做一个统计方法的js
  • sk360c #2 · 2020-06-22 16:16:17
    要想不改主程序只能复制出来改api控制器类文件
  • 龙媒 #3 · 2020-06-22 16:31:06
    sk360c 如果这样改的话,怎么收费?
  • 靠悬赏赚钱买授权 #4 · 2020-06-22 16:36:49
    5元赏金,我按一楼思路给你改,不影响升级
  • 龙媒 #5 · 2020-06-22 16:38:12
    靠悬赏(设置悬赏)赚钱买授权 可以,需要我重新发个悬赏(设置悬赏)贴吗?
  • 靠悬赏赚钱买授权 #6 · 2020-06-22 16:40:09
    追加悬赏(设置悬赏)金额
  • 靠悬赏赚钱买授权 #7 · 2020-06-22 16:49:10
    满意答案
    1、config/custom.php
    function dr_show_hits($id, $dom = "", $dir = MOD_DIR) {
          $is = $dom;
          !$dom && $dom = "dr_show_hits_{$id}";
          $html = $is ? "" : "<span id=\"{$dom}\">0</span>";
          return $html."<script type=\"text/javascript\">
    $.ajax({
       type: \"GET\",
       url:\"".ROOT_URL."index.php?s=api&c=mymodule&siteid=".SITE_ID."&app=".$dir."&m=hits&id={$id}\",
       dataType: \"jsonp\",
       success: function(data){
          if (data.code) {
             $(\"#{$dom}\").html(data.msg);
          } else {
             dr_tips(0, data.msg);
          }
       }
    });
      </script>";
      }
    2、复制文件dayrui/Core/Controllers/Api/Module.php,到,dayrui/Core/Controllers/Api/Mymodule.php内如如下:
    <?php namespace Phpcmf\Controllers\Api;
    
    // 模块ajax操作接口
    class Mymodule extends \Phpcmf\Common
    {
        private $siteid;
        private $dirname;
        private $tablename;
    
        protected $content_model;
    
        public function __construct(...$params) {
            parent::__construct(...$params);
            // 初始化模块
            $this->siteid = (int)\Phpcmf\Service::L('input')->get('siteid');
            !$this->siteid && $this->siteid = SITE_ID;
            $this->dirname = dr_safe_replace(\Phpcmf\Service::L('input')->get('app'));
            if (!$this->dirname || !dr_is_app_dir(($this->dirname))) {
                $this->_msg(0, dr_lang('模块目录[%s]不存在', $this->dirname));
                exit;
            }
            $this->tablename = $this->siteid.'_'.$this->dirname;
            $this->content_model = \Phpcmf\Service::M('Content', $this->dirname);
            $this->_module_init($this->dirname, $this->siteid);
        }
    
        /**
         * 阅读数统计
         */
        public function hits() {
    
            $id = (int)\Phpcmf\Service::L('input')->get('id');
            if (!$id) {
                $this->_jsonp(0, dr_lang('阅读统计: id参数不完整'));
            }
    
            $data = \Phpcmf\Service::M()->db->table($this->tablename)->where('id', $id)->select('hits,updatetime')->get()->getRowArray();
            if (!$data) {
                $this->_jsonp(0, dr_lang('阅读统计: 模块内容不存在'));
            }
    
            $plus = defined('IS_HITS_PLUS') && is_numeric(IS_HITS_PLUS) ? intval(IS_HITS_PLUS) : 1;
            if (!$plus) {
                // 增量为0时原样输出
                $this->_jsonp(1, $data['hits']);exit;
            }
    
            $hits = (int)$data['hits'] + $plus;
    
            // 更新主表
            \Phpcmf\Service::M()->db->table($this->tablename)->where('id', $id)->set('hits', $hits)->update();
    
            // 获取统计数据
            $total = \Phpcmf\Service::M()->db->table($this->tablename.'_hits')->where('id', $id)->get()->getRowArray();
            if (!$total) {
                $total['day_hits'] = $total['week_hits'] = $total['month_hits'] = $total['year_hits'] = 0;
                $total['day_time'] = $total['week_time'] = $total['month_time'] = $total['year_time'] = SYS_TIME;
            } else {
                // 按类别归零
                if (date('Ymd', $total['day_time']) != date('Ymd', SYS_TIME)) {
                    $total['day_time'] = SYS_TIME;
                    $total['day_hits'] = 0;
                }
                if (date('YW', $total['week_time']) != date('YW', SYS_TIME)) {
                    $total['week_time'] = SYS_TIME;
                    $total['week_hits'] = 0;
                }
                if (date('Ym', $total['month_time']) != date('Ym', SYS_TIME)) {
                    $total['month_time'] = SYS_TIME;
                    $total['month_hits'] = 0;
                }
                if (date('Y', $total['year_time']) != date('Y', SYS_TIME)) {
                    $total['year_time'] = SYS_TIME;
                    $total['year_hits'] = 0;
                }
            }
    
            // 更新到统计表
            $save = [
                'id' => $id,
                'hits' => $hits,
                'day_hits' => $total['day_hits'] + $plus,
                'day_time' => $total['day_time'],
                'week_hits' => $total['week_hits'] + $plus,
                'week_time' => $total['week_time'],
                'month_hits' => $total['month_hits'] + $plus,
                'month_time' => $total['month_time'],
                'year_hits' => $total['year_hits'] + $plus,
                'year_time' => $total['year_time'],
            ];
            \Phpcmf\Service::M()->table($this->tablename.'_hits')->replace($save);
    
    
            // 输出
            $this->_jsonp(1, $hits);
        }
    
    
    
    }
  • 龙媒 #8 · 2020-06-22 16:49:25
    靠悬赏(设置悬赏)赚钱买授权 你做好了我再加,还是我现在加悬赏(设置悬赏)?
  • 龙媒 #9 · 2020-06-22 16:52:29

    靠悬赏(设置悬赏)赚钱买授权 我等会试下。先谢谢了
  • 龙媒 #10 · 2020-06-22 18:43:17
    靠悬赏(设置悬赏)赚钱买授权 试过了不行啊,有问题,可以加QQ联系吗:351703406
  • 小黄人 18html.com #11 · 2020-06-22 19:04:13
    真复杂,写一个update,然后写一小段js就完事了
  • 迅睿框架创始人 #12 · 2020-06-22 21:30:35
    五楼的代码和方法很完美了,非常不错
  • 龙媒 #13 · 2020-06-23 14:00:47
    增加悬赏(设置悬赏)金:5元,希望大家给予帮助!
  • 龙媒 #14 · 2020-06-23 14:01:35
    靠悬赏(设置悬赏)赚钱买授权 直接使用你的代码,可是报错,怎么回事?
  • 小黄人 18html.com #15 · 2020-06-23 16:32:12
    回复迅睿框架创始人五楼的代码,确实是不行的!500错误
    <?php namespace Phpcmf\Controllers\Api;
    
    /**
     * http://www.xunruicms.com
     * 本文件是框架系统文件,二次开发时不可以修改本文件
     **/
    
    
    
    // 模块ajax操作接口
    class Mymodule extends \Phpcmf\Common
    {
        private $siteid;
        private $dirname;
        private $tablename;
    
        protected $content_model;
    
        public function __construct(...$params) {
            parent::__construct(...$params);
            // 初始化模块
            $this->siteid = (int)\Phpcmf\Service::L('input')->get('siteid');
            !$this->siteid && $this->siteid = SITE_ID;
            $this->dirname = dr_safe_replace(\Phpcmf\Service::L('input')->get('app'));
            if (!$this->dirname || !dr_is_app_dir(($this->dirname))) {
                $this->_msg(0, dr_lang('模块目录[%s]不存在', $this->dirname));
                exit;
            }
            $this->tablename = $this->siteid.'_'.$this->dirname;
            $this->content_model = \Phpcmf\Service::M('Content', $this->dirname);
            $this->_module_init($this->dirname, $this->siteid);
        }
    
        public function index() {
            exit('module api');
        }
    
        /**
         * 阅读数统计
         */
        public function hits() {
    
            $id = (int)\Phpcmf\Service::L('input')->get('id');
            if (!$id) {
                $this->_jsonp(0, dr_lang('阅读统计: id参数不完整'));
            }
    
            $data = \Phpcmf\Service::M()->db->table($this->tablename)->where('id', $id)->select('hits,updatetime')->get()->getRowArray();
            if (!$data) {
                $this->_jsonp(0, dr_lang('阅读统计: 模块内容不存在'));
            }
    
            $plus = defined('IS_HITS_PLUS') && is_numeric(IS_HITS_PLUS) ? intval(IS_HITS_PLUS) : 1;
            if (!$plus) {
                // 增量为0时原样输出
                $this->_jsonp(1, $data['hits']);exit;
            }
    /*
            $name = 'module-'.md5($this->tablename).'-'.$id;
            if (\Phpcmf\Service::L('input')->get_cookie($name)) {
                $this->_jsonp(1, $data['hits']);
            }
    */
            $hits = (int)$data['hits'] + $plus;
    
            // 更新主表
            \Phpcmf\Service::M()->db->table($this->tablename)->where('id', $id)->set('hits', $hits)->update();
    
            // 获取统计数据
            $total = \Phpcmf\Service::M()->db->table($this->tablename.'_hits')->where('id', $id)->get()->getRowArray();
            if (!$total) {
                $total['day_hits'] = $total['week_hits'] = $total['month_hits'] = $total['year_hits'] = $plus;
            }
    
            // 更新到统计表
            \Phpcmf\Service::M()->table($this->tablename.'_hits')->replace([
                'id' => $id,
                'hits' => $hits,
                'day_hits' => (date('Ymd', $data['updatetime']) == date('Ymd', SYS_TIME)) ? $hits : $plus,
                'week_hits' => (date('YW', $data['updatetime']) == date('YW', SYS_TIME)) ? ($total['week_hits'] + $plus) : $plus,
                'month_hits' => (date('Ym', $data['updatetime']) == date('Ym', SYS_TIME)) ? ($total['month_hits'] + $plus) : $plus,
                'year_hits' => (date('Ymd', $data['updatetime']) == date('Ymd', strtotime('-1 day'))) ? $hits : $total['year_hits'],
            ]);
    
            //session()->save($name, $id, 300); 考虑并发性能还是不用session了
            //\Phpcmf\Service::L('input')->set_cookie($name, $id, 300);
            \Phpcmf\Service::M()->table($this->tablename.'_hits')->replace($save);
    
            // 输出
            $this->_jsonp(1, $hits);
        }
    
    }
  • 靠悬赏赚钱买授权 #16 · 2020-06-23 16:57:32
    什么错误呢,我运行一切正常龙媒
  • 龙媒 #17 · 2020-06-23 18:03:05
    @靠悬赏(设置悬赏)赚钱买授权:代码出错,跟着思路改好了。

迅睿系统漏洞

独立站群系统
独立站群系统(2026-09-14)
子站独立部署时修复同步附件失败问题
在线客服
在线客服(2026-09-13)
修复删除会话报错问题 删除会话时联动删除聊天图片
在线考试竞赛系统
在线考试竞赛系统(2026-09-12)
增加投票功能 考试功能拓展 注意:更新后需要执行系统更新,更新数...
网上信箱
网上信箱(2026-09-12)
修复新版本兼容问题
GeoSeo收录宝
GeoSeo收录宝(2026-09-12)
1 优化Update.php文件,解决版本在线升级不完整问题 2 ...
GeoSeo工具箱
GeoSeo工具箱(2026-09-11)
修正历史记录推送
微信系统
微信系统(2026-09-11)
增加数据统计总览界面 账号管理增加服务和公众号的区别 菜单管理支持更...
答题系统
答题系统(2026-09-11)
一站式在线答题系统,支持真题考试、题库练习和错题本,适合培训、考证、...
阿里云滑动验证码
阿里云滑动验证码(2026-09-10)
采用阿里云验证码替换迅睿系统自带的图片验证码和滑动验证码。后台设置方...
下载Plus
下载Plus(2026-09-09)
为网站附件下载加上“计数、限次、统计、防护”四重能力:按用户组控制下...