Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // * Auto IP Ban Script - v1.0 *
- // * Author: Inque187 *
- // * Date: (c) Oct 5, 2007 *
- // * Works with PHP 4.0+ & 5.0+ *
- // * 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 *
- // * 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 *
- // * 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. *
- $ipad = $_SERVER['REMOTE_ADDR']; // Collects the user/visitor IP address.
- $ban = "Deny from $ipad\n"; // What will be written to the .htaccess file if IP needs to be banned.
- $file = ".htaccess"; // Change to -> .htaccess <- once thoroughly tested. Should be placed in the root directory.
- $search = file_get_contents($file); // Prepare the .htaccess file by gathering entire contents.
- $check = strpos($search, $ipad); // Checks the .htaccess file if the current user IP address string does exist.
- // This next part of the script checks to see if the IP is already banned or not.
- // 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.
- // If the IP is already listed in the .htaccess file; the script ends with only a displayed message.
- if ($check === FALSE) {
- $open = @fopen($file, "a"); // Open the .htaccess file and get ready for writing only.
- $write = @fputs($open, $ban); // Write the banned IP line to the .htaccess file. (Example: Deny from 12.34.56.789)
- // Email a copy of ban and info to your admin account (or other email address).
- // Make sure you change the email address.
- @mail('webmaster@yourdomain.com','yourdomain.com: Banned IP '.$_SERVER['REMOTE_ADDR'].'','
- Banned IP: '.$_SERVER['REMOTE_ADDR'].'
- Request URL: '.$_SERVER['REQUEST_URI'].'
- User Agent: '.$_SERVER['HTTP_USER_AGENT']);
- // IP address is not banned - so there is a need to write to .htaccess file.
- // Display the error message to the user. (You may change to read what you want).
- 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>';
- // Close the .htaccess file - all done.
- @fclose($open);
- } else {
- // IP address is already banned - no need to rewrite to .htaccess file.
- // Display the error message to the user. (You may change to read what you want).
- 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>';
- }
- // End of File/Script;
- exit;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement