Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $file = "banned.txt";
- $ip = $_SERVER[REMOTE_ADDR];
- # delete banned.txt if more than 100 entries
- # to keep file from filling up with ips
- if (file_exists($file))
- {
- $array = file($file);
- $count = count($array);
- if ($count > 100)
- {
- unlink($file);
- }
- }
- # create banned.txt if not created and log ip
- file_put_contents($file, "$ip\n", FILE_APPEND);
- # open banned.txt and check matching ips
- $myArray = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
- $newArray = array_count_values($myArray);
- # find the largest number of matching ips
- $lrgst = max($newArray);
- # if over 5 hits by same ip, redirect to trap.pl
- # and delete banned.txt
- if ($lrgst >= 5)
- {
- unlink($file);
- header("location:http://yourdomain.com/cgi-bin/trap.pl");
- exit;
- } else {
- # if same ip hasn't hit the 404 page over 5 times
- # return 404 page
- $nopage = <<<HEREDOC
- <html>
- <head><title>404 Not Found</title></head>
- <body>
- The Page You Requested Could Not Be Found
- </body>
- </html>
- HEREDOC;
- echo $nopage;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment