Guest User

Untitled

a guest
Dec 23rd, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. <?php
  2. $file = "banned.txt";
  3. $ip = $_SERVER[REMOTE_ADDR];
  4.  
  5. # delete banned.txt if more than 100 entries
  6. # to keep file from filling up with ips
  7. if (file_exists($file))
  8. {
  9. $array = file($file);
  10. $count = count($array);
  11. if ($count > 100)
  12. {
  13. unlink($file);
  14. }
  15. }
  16.  
  17. # create banned.txt if not created and log ip
  18. file_put_contents($file, "$ip\n", FILE_APPEND);
  19.  
  20. # open banned.txt and check matching ips
  21. $myArray = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  22. $newArray = array_count_values($myArray);
  23.  
  24. # find the largest number of matching ips
  25. $lrgst = max($newArray);
  26.  
  27. # if over 5 hits by same ip, redirect to trap.pl
  28. # and delete banned.txt
  29. if ($lrgst >= 5)
  30. {
  31. unlink($file);
  32. header("location:http://yourdomain.com/cgi-bin/trap.pl");
  33. exit;
  34.  
  35. } else {
  36.  
  37. # if same ip hasn't hit the 404 page over 5 times
  38. # return 404 page
  39. $nopage = <<<HEREDOC
  40. <html>
  41. <head><title>404 Not Found</title></head>
  42. <body>
  43. The Page You Requested Could Not Be Found
  44. </body>
  45. </html>
  46. HEREDOC;
  47. echo $nopage;
  48. }
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment