Advertisement
OneTallor

Untitled

Oct 9th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. //if user does not change IP, then ban the IP when more than 10 requests per second are detected in 1 second
  2. $limitps = 10;
  3. if (!isset($_SESSION['first_request'])){
  4. $_SESSION['requests'] = 0;
  5. $_SESSION['first_request'] = $_SERVER['REQUEST_TIME'];
  6. }
  7. $_SESSION['requests']++;
  8. if ($_SESSION['requests']>=10 && strtotime($_SERVER['REQUEST_TIME'])-strtotime($_SESSION['first_request'])<=1){
  9. //write the IP to a banned_ips.log file and configure your server to retrieve the banned ips from there - now you will be handling this IP outside of PHP
  10. $_SESSION['banip']==1;
  11. }elseif(strtotime($_SERVER['REQUEST_TIME'])-strtotime($_SESSION['first_request']) > 2){
  12. $_SESSION['requests'] = 0;
  13. $_SESSION['first_request'] = $_SERVER['REQUEST_TIME'];
  14. }
  15.  
  16. if ($_SESSION['banip']==1) {
  17. header('HTTP/1.1 503 Service Unavailable');
  18. die;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement