Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

ban.php

By: a guest on Feb 4th, 2012  |  syntax: PHP  |  size: 3.15 KB  |  views: 437  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. // * Auto IP Ban Script - v1.0 *
  3. // * Author: Inque187 *
  4. // * Date: (c) Oct 5, 2007 *
  5. // * Works with PHP 4.0+ & 5.0+ *
  6.  
  7. // * DISCLAIMER: Author of this script is not and will not be held liable and or responsibile for any configuration errors, loss of data, interruption of *
  8. // * service, and or any other means of misuse by neglect pertaining to this script that affects any internet account. User of this script takes sole *
  9. // * responsibility for any resulting problems that arise due to usage of this script in part or in whole and shall hold indemnity against the author. *
  10.  
  11. $ipad = $_SERVER['REMOTE_ADDR'];        // Collects the user/visitor IP address.
  12. $ban = "Deny from $ipad\n";                     // What will be written to the .htaccess file if IP needs to be banned.
  13. $file = ".htaccess";                                    // Change to -> .htaccess <- once thoroughly tested. Should be placed in the root directory.
  14. $search = file_get_contents($file);             // Prepare the .htaccess file by gathering entire contents.
  15. $check = strpos($search, $ipad);                // Checks the .htaccess file if the current user IP address string does exist.
  16.  
  17. // This next part of the script checks to see if the IP is already banned or not.
  18. // If the IP does not already exist; it will write the ban line to the .htaccess file, display the message, and then email you a copy.
  19. // If the IP is already listed in the .htaccess file; the script ends with only a displayed message.
  20. if ($check === FALSE) {
  21.  
  22. $open = @fopen($file, "a");                     // Open the .htaccess file and get ready for writing only.
  23. $write = @fputs($open, $ban);           // Write the banned IP line to the .htaccess file. (Example: Deny from 12.34.56.789)
  24.  
  25. // Email a copy of ban and info to your admin account (or other email address).
  26. // Make sure you change the email address.
  27. @mail('webmaster@yourdomain.com','yourdomain.com: Banned IP '.$_SERVER['REMOTE_ADDR'].'','
  28. Banned IP: '.$_SERVER['REMOTE_ADDR'].'
  29. Request URL: '.$_SERVER['REQUEST_URI'].'
  30. User Agent: '.$_SERVER['HTTP_USER_AGENT']);
  31.  
  32. // IP address is not banned - so there is a need to write to .htaccess file.
  33. // Display the error message to the user. (You may change to read what you want).
  34.         echo '<html><head><title>IP Address '.$ipad.' - Blocked or Banned!</title></head><body bgcolor="#FF000000" text="#FFFFFF" oncontextmenu="return false;"><center><font face="Verdana, Arial"><h1>THANK YOU - DON\'T COME AGAIN!</h1><b>IP Address '.$ipad.' Has Been Blocked or Banned!<br />Contact the web admin if this ban is by mistake.<p />Have a nice day!</b></font></center></body></html>';
  35.  
  36. // Close the .htaccess file - all done.
  37. @fclose($open);
  38. } else {
  39.  
  40. // IP address is already banned - no need to rewrite to .htaccess file.
  41. // Display the error message to the user. (You may change to read what you want).
  42.         echo '<html><head><title>IP Address '.$ipad.' - Blocked or Banned!</title></head><body bgcolor="#FF000000" text="#FFFFFF" oncontextmenu="return false;"><center><font face="Verdana, Arial"><h1>THANK YOU - DON\'T COME AGAIN!</h1><b>IP Address '.$ipad.' Has Been Blocked or Banned!<br />Contact the web admin if this ban is by mistake.<p />Have a nice day!</b></font></center></body></html>';
  43. }
  44.  
  45. // End of File/Script;
  46. exit;
  47. ?>