Plugin Sale! Save 15% on pro plugins with discount code: NEWYEAR2021
Web Dev + WordPress + Security

Blackhole for Bad Bots – Quick Start

[ Black Hole (Figurative) ] Welcome to the Quick Start Guide for the standalone PHP version of Blackhole for Bad Bots. This post basically is a condensed summary of the original Blackhole tutorial. So if you are new to the concept of blocking bad bots, check out the original tutorial. Otherwise, for those that are familiar, the following guide should simplify things and help you get started with Blackhole as quickly as possible.

Trap bad bots in a virtual black hole

Bad bots are the worst. They steal server resources from legit visitors. We hates them and wants to block them. The Blackhole for Bad Bots does exactly that: blocks bad bots by trapping them in a virtual black hole. It’s a simple technique that is proven effective.

Here’s how it works: you add a hidden link to your site. You instruct bots to NOT follow that link. Any bots that disobey will be logged and denied further access. It’s that simple. To learn more, demo, and download, check out the original Blackhole tutorial.

Standalone PHP Version

[ Blackhole for Bad Bots ] This article explains how to use the standalone PHP version of Blackhole for Bad Bots. For more in-depth instructions and information, check out the original Blackhole tutorial. If you are running WordPress, the Blackhole plugin is recommended; it is easier to set up and provides a lot more functionality.

For the standalone PHP version, the zip download includes a /blackhole/ directory that contains three files:

  • .htaccess – protects the log file
  • blackhole.dat – log file
  • index.php – blackhole script

These three files work together to create the Blackhole for Bad Bots. The .htaccess file is hidden on most systems, so if needed check out this tutorial for more infos.

Pro version! Using WordPress? Check out Blackhole Pro »

Installation

Here are the steps to install the Blackhole PHP script. Note that this applies to Blackhole version 4.0 and better. For older versions, refer to the original Blackhole tutorial. With that in mind, here are the installation steps:

Step 1

Download the Blackhole zip file. Unzip the file, and add the /blackhole/ folder to the root directory of your site.

Step 2

Open the index.php file, and edit the three variables in the “EDIT HERE” section.

Step 3

Change file permissions on the blackhole.dat log file, so that it’s writable by the server. Don’t worry, the .htaccess file contains rules that protect the log file from all external access.

Step 4

Include the Blackhole script by adding this line to all of your site’s pages:

<?php include(realpath(getenv('DOCUMENT_ROOT')) . '/blackhole/index.php'); ?>

That line should be placed at the top of any PHP file that displays a web page (e.g., header.php). For more information, check out the Troubleshooting notes in the original tutorial.

Step 5

Add the following line to the footer of all pages (e.g., footer.php):

<a rel="nofollow" style="display:none;" href="https://example.com/blackhole/">Do NOT follow this link or you will be banned from the site!</a>

Remember to change the href value to match the URL of your domain.

Step 6

Add these lines to your site’s robots.txt file:

User-agent: *
Disallow: /blackhole/

Note: It is important to get your robots rules correct. Please use a robots validator to verify proper syntax.

Step 7

Done! Remember to test thoroughly before going live.

Testing

You can verify that the script is working by visiting the hidden Blackhole link (added in step 5). That should take you to the Blackhole warning page, and block you from further access. To verify that you’ve been blocked, try visiting another page on your site. To restore site access, you can clear the contents of the blackhole.dat log file. Again, more details available in the original Blackhole tutorial.

Important: Make sure that all of the rules in your robots.txt file are correct and have proper syntax. For example, you can use the free robots.txt validator in Google Webmaster Tools (requires Google account).

Download

For complete information and free download, check out the original Blackhole tutorial here at Perishable Press.

Jeff Starr
About the Author
Jeff Starr = Web Developer. Book Author. Secretly Important.
Banhammer: Protect your WordPress site against threats.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
WP Themes In Depth: Build and sell awesome WordPress themes.
Thoughts
Simply Static is my go-to plugin for generating static HTML versions of WordPress sites. Works flawlessly.
Note to self: never, ever, ever buy any CD or DVD from eBay. Every single time the discs are scratched, damaged, missing, fake, or worse. Never again you clowns.
Find out if a plugin works with the latest version of WordPress @ plugintests.com
Going through all of my data, deleting all the chaff. Going for less than 500 GB total data storage.
Finally deleted all the cool unused placeholder Twitter accounts that I signed up for years ago. I will never use them.
After several years with Dashlane, I've moved on to a simpler, better solution.
After 10+ years, finally moved the last of my sites away from Media Temple.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.