BrowserCheckBehavior.class.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace Behavior;
  12. /**
  13. * 浏览器防刷新检测
  14. */
  15. class BrowserCheckBehavior {
  16. public function run(&$params) {
  17. if($_SERVER['REQUEST_METHOD'] == 'GET') {
  18. // 启用页面防刷新机制
  19. $guid = md5($_SERVER['PHP_SELF']);
  20. // 浏览器防刷新的时间间隔(秒) 默认为10
  21. $refleshTime = C('LIMIT_REFLESH_TIMES',null,10);
  22. // 检查页面刷新间隔
  23. if(cookie('_last_visit_time_'.$guid) && cookie('_last_visit_time_'.$guid)>time()-$refleshTime) {
  24. // 页面刷新读取浏览器缓存
  25. header('HTTP/1.1 304 Not Modified');
  26. exit;
  27. }else{
  28. // 缓存当前地址访问时间
  29. cookie('_last_visit_time_'.$guid, $_SERVER['REQUEST_TIME']);
  30. //header('Last-Modified:'.(date('D,d M Y H:i:s',$_SERVER['REQUEST_TIME']-C('LIMIT_REFLESH_TIMES'))).' GMT');
  31. }
  32. }
  33. }
  34. }