Fall Sale! Code FALL2024 takes 25% OFF our Pro Plugins & Books »
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.

About the Author
Jeff Starr = Fullstack Developer. Book Author. Teacher. Human Being.
Blackhole Pro: Trap bad bots in a virtual black hole.
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 »
The Tao of WordPress: Master the art of WordPress.
Thoughts
I disabled AI in Google search results. It was making me lazy.
Went out walking today and soaked up some sunshine. It felt good.
I have an original box/packaging for 2010 iMac if anyone wants it free let me know.
Always ask AI to cite its sources. Also: “The Web” is not a valid answer.
All free plugins updated and ready for WP 6.6 dropping next week. Pro plugin updates in the works also complete :)
99% of video thumbnail/previews are pure cringe. Goofy faces = Clickbait.
RIP ICQ
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.