Okay, this is a very crude way to block bots, spiders and crawlers by their user-agent, but so far, this has been very, very efficient.
Even when one chooses ” yes “, the question will be repeated. This is not a problem, because no one in their right mind is going to add “bot”, “spider” or “crawler” as their user-agent.
So here’s the PHP script that I rammed into a certain website to prevent it from being DDOSsed by (malicious) bots.
<?php // Emergency bypass // goto end; ///////////////////////////////////////////////////////////// // (c) FoxSAIn 2023, Free to use. ///////////////////////////////////////////////////////////// // Function to check if the user agent appears to be a bot or spider. // Enter the bots you would like to block in a list as shown below. function isBot() { $user_agent = $_SERVER["HTTP_USER_AGENT"]; $bot_keywords = [ "bytespider", "amazonbot", "mj12bot", "YandexBot", "SemrushBot", "AhrefsBot" ]; foreach ($bot_keywords as $keyword) { if (stripos($user_agent, $keyword) !== false) { return true; } } return false; } // Check if the visitor is a bot or spider if (isBot()) { // This visitor appears to be a bot or spider, so display a choice. // Check if the choice form is submitted if (isset($_POST["submit"])) { // Check the choice made by the visitor $choice = isset($_POST["choice"]) ? $_POST["choice"] : ""; if ($choice === "yes") { // User selected "Yes," block access echo "Access denied. If you believe this is an error, please contact us by writing the word support before the at sign, followed by 4-stroke.net"; } elseif ($choice === "no") { // User selected "No," proceed to end goto end; } } else { // Output the message to the user and make the choice mandatory echo "Your user agent suggests you might be a bot, spider, or crawler. Are you one of these three?"; // Output the radio button choices within a form echo '</p> <form method="post" action="">'; echo ' <label><input type="radio" name="choice" value="yes" required>Yes</label>'; echo ' <label><input type="radio" name="choice" value="no">No</label>'; echo ' <button type="submit" name="submit">Proceed</button>'; echo "</form> <p>"; } // Exit to prevent further processing exit(); } end: // Original website code starts from here. ///////////////////////////////////////////////////////////// ?>