Home >Backend Development >PHP Tutorial >Prevent web pages from being refreshed frequently by users_PHP Tutorial
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(); ?> 以上代码在真实的用户环境下,是可以实现的