.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 'IP Address '.$ipad.' - Blocked or Banned!

THANK YOU - DON\'T COME AGAIN!

IP Address '.$ipad.' Has Been Blocked or Banned!
Contact the web admin if this ban is by mistake.

Have a nice day!

'; // 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 'IP Address '.$ipad.' - Blocked or Banned!

THANK YOU - DON\'T COME AGAIN!

IP Address '.$ipad.' Has Been Blocked or Banned!
Contact the web admin if this ban is by mistake.

Have a nice day!

'; } // End of File/Script; exit; ?>