Home >Backend Development >PHP Tutorial >Prevent web pages from being refreshed frequently by users_PHP Tutorial

Prevent web pages from being refreshed frequently by users_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 14:53:381208browse

Under normal circumstances, users browse web pages at a speed of several seconds, ten seconds or even longer to refresh a page. However, sometimes web pages are maliciously refreshed quickly, resulting in slow browsing speed for normal users. , how to solve this problem? You can use the following code to limit the number of page visits per 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();
?>
以上代码在真实的用户环境下,是可以实现的

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371358.htmlTechArticleGenerally, users browse web pages at a speed of several seconds, ten seconds or even longer to refresh a page. But sometimes we encounter web pages that are maliciously refreshed quickly, causing normal users to browse faster...
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