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
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.
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:
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 Troubleshooting notes in the original 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. Again, more details available in the original Blackhole tutorial.
For complete information and free download, check out the original Blackhole tutorial here at Perishable Press.