This post summarizes Blackhole for Bad Bots version 4.0+. For older versions, check out the original tutorial. Please read the original tutorial for download, demo, and important information about the standalone PHP version of Blackhole for Bad Bots. The following guide is meant to simplify things for users of Blackhole version 4.0 and better.
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
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.
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.
Here are the steps to install the Blackhole PHP script. Note that this applies to Blackhole version 4.0 and greater. For older versions, refer to the original blackhole tutorial. With that in mind, here are the steps:
Download the Blackhole zip file. Unzip the file, and add the
/blackhole/ folder to the root directory of your site.
index.php file, and edit the three variables in the “EDIT HERE” section.
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.
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 section, “File Path”, in the original blackhole tutorial.
Add the following line to the footer of all pages (e.g.,
<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.
Add these lines to your site’s
User-agent: * Disallow: /blackhole/
Note: It is important to get your robots rules correct. Please use a robots validator to verify proper syntax.
Done! Remember to test thoroughly before going live.
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.
For complete information and free download, check out the original Blackhole tutorial here at Perishable Press.