Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

施宇 / icsales

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
BlameHistoryPermalink
Switch branch/tag
  • icsales
  • ThinkPHP
  • Library
  • Behavior
  • BrowserCheckBehavior.class.php
  • 施宇's avatar
    init · 14f95149
    施宇 committed 6 years ago
    14f95149
BrowserCheckBehavior.class.php 1.55 KB
Edit
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Behavior;

/**
 * 浏览器防刷新检测
 */
class BrowserCheckBehavior
{
    public function run(&$params)
    {
        if ('GET' == $_SERVER['REQUEST_METHOD']) {
            //    启用页面防刷新机制
            $guid = md5($_SERVER['PHP_SELF']);
            // 浏览器防刷新的时间间隔(秒) 默认为10
            $refleshTime = C('LIMIT_REFLESH_TIMES', null, 10);
            // 检查页面刷新间隔
            if (cookie('_last_visit_time_' . $guid) && cookie('_last_visit_time_' . $guid) > time() - $refleshTime) {
                // 页面刷新读取浏览器缓存
                header('HTTP/1.1 304 Not Modified');
                exit;
            } else {
                // 缓存当前地址访问时间
                cookie('_last_visit_time_' . $guid, $_SERVER['REQUEST_TIME']);
                //header('Last-Modified:'.(date('D,d M Y H:i:s',$_SERVER['REQUEST_TIME']-C('LIMIT_REFLESH_TIMES'))).' GMT');
            }
        }
    }
}