Home  >  Article  >  php教程  >  阻止网页被用户频繁刷新

阻止网页被用户频繁刷新

WBOY
WBOYOriginal
2016-06-13 11:36:13925browse

 一般情况下,用户浏览网页的速度都是几秒十几秒甚至更长时间刷新一页,但有时候又会遇到网页被恶意快速刷新,从而导致正常用户浏览速度缓慢,如何来解决这个问题呢?可以使用如下代码来实现每ip页面访问数量限制:

<?php $min_seconds_between_refreshes = 3;#设置刷新的时间

session_start();

if(array_key_exists('last_access', $_SESSION) && time()-$min_seconds_between_refreshes <= $_SESSION['last_access'])
 {
  // The user has been here at least $min_seconds_between_refreshes seconds ago - block them
  exit('You are refreshing too quickly, please wait a few seconds and try again.');
}
// Record now as their last access time
$_SESSION['last_access'] = time();
?>
以上代码在真实的用户环境下,是可以实现的
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn