编程爱好者之家
//防刷处理 $access_count=accessCountLimit(); if ($access_count) { die; } /** * 频繁提交总控制,30分钟20次 */ function accessCountLimit($limit=30, $time=1800) { $result=false; if (!isset($_SESSION)) { session_start(); } if (!isset($_SESSION['access_count'])) { $_SESSION['access_count']=1; } if (!isset($_SESSION['last_access']) || (time()-$_SESSION['last_access'])>$time) { $_SESSION['last_access']=time(); $_SESSION['access_count']=1; } $_SESSION['access_count']=(int)$_SESSION['access_count']+1; if ((int)$_SESSION['access_count']>$limit || accessCountLimitPerMinute()) { $result=true; } return $result; } /** * 频繁提交 1分钟4次 */ function accessCountLimitPerMinute($limit=10, $time=60) { $result=false; if (!isset($_SESSION)) { session_start(); } if (!isset($_SESSION['access_count_minute'])) { $_SESSION['access_count_minute']=1; } if (!isset($_SESSION['last_access_minute']) || (time()-$_SESSION['last_access_minute'])>$time) { $_SESSION['last_access_minute']=time(); $_SESSION['access_count_minute']=1; } $_SESSION['access_count_minute']=(int)$_SESSION['access_count_minute']+1; if ((int)$_SESSION['access_count_minute']>$limit) { $result=true; } return $result; }