// // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Script to block robots from a site (or part of it). // // To set it up, stick this script in the root of the heirachy you are // protecting, and add the following lines to your .htaccess (assuming // that the script is called botfree.php and in the root of the // server): // // # Setup the URL rewriting engine. // RewriteEngine On // RewriteBase / // // # Block all robots // RewriteRule ^robots\.txt$ - [L] // RewriteRule ^botfree\.php$ - [L] // RewriteRule ^botfree-set$ botfree.php [L] // RewriteRule ^botfree-check botfree.php [L] // RewriteCond %{HTTP_COOKIE} !HUMAN=yes [NC] // RewriteRule ^(.*)$ botfree.php [L] // // The method used would be easy to forge; if this script ever became // widespread then you'd probably need to do something with images. // URLs $SETURL = substr($_SERVER['PHP_SELF'], 0, -4) . '-set'; $CHKURL = substr($_SERVER['PHP_SELF'], 0, -4) . '-check'; // Utility functions function bf_die($error) { header('HTTP/1.1 $error'); die("$error\n"); } function bf_decode_getvar($name) { if (!isset($_GET[$name])) bf_die('400 Bad Request'); return $_GET[$name]; } function bf_decode_6d_getvar($name) { $var = bf_decode_getvar($name); if (!preg_match('/^\d{6}$/', $_GET[$name])) bf_die('400 Bad Request'); return $_GET[$name]; } function bf_redirect($relurl) { $url = 'http://'; $url .= $_SERVER['SERVER_NAME']; $port = $_SERVER['SERVER_PORT']; if ($port != 80) $url .= ":$port"; $url .= $relurl; header('HTTP/1.1 302 Found'); header("Location: $url"); ?>
To prove that you are human please enter the six-digit number from the blue box into the textbox and hit continue. $reloader = ""; if (substr($_SERVER['HTTP_USER_AGENT'], 0, 6) == 'Elinks') $reloader = "Links"; if ($reloader) { ?> Since you are using = $reloader ?> you may have to reload the page afterwards. } ?> This is in order to prevent robots (specifically badly behaved robots) from spidering this site.
Why? Well, the main reason is that I don't want the content of this site ending up on any search engines. Search engines use programs called robots to gather webpages for indexing, robots which are supposed to respect the Robots Exclusion Standard. Well-behaved robots that do just that will not attempt to spider this site. Unfortunatly, not all robots are so well-behaved, and this page is designed to stop them in their tracks: robots can't read and follow instructions just yet!
As well as search engines' bots this test also stops the more insidious bots such as spambots, which harvest email addresses, and spybots, which try to hunt for percieved violations of copyright or trademark law. Stopping them was not the primary aim of this test, but the fact that it does pleases me nontheless.
On other sites I passively block bad robots and ignore badly-behaved search engines, but my wish that nothing on ths site ever gets indexed means that I have to employ more draconian measures. I apologise to my readers for this small indignity. For more information about blocking bad robots please refer to Mark Pilgrim's excellent How to block spambots, ban spybots, and tell unwanted robots to go to hell.
bf_pagefooter(); } // Stage 2: set the cookie function bf_setcookie() { $bounce = bf_decode_getvar('bounce'); if (bf_decode_6d_getvar('actual') != bf_decode_6d_getvar('expected')) { bf_pageheader(); ?>Whoops, you got it wrong. If you are human then please feel free to go back and try again.
bf_pagefooter(); } else { setcookie('HUMAN', 'yes', time() + 315360000); bf_redirect($GLOBALS['CHKURL'] . '?bounce=' . urlencode($bounce)); } } // Stage 3: check that the cookie was set function bf_testcookie() { $bounce = bf_decode_getvar('bounce'); if ($_COOKIE['HUMAN'] == 'yes') { bf_redirect(urldecode($bounce)); } else { bf_pageheader(); ?>I tried to set a cookie to indicate that you are a human and not a robot, but I failed. Please enable cookies in your browser and try again.
bf_pagefooter(); } } // marshal the request $request_uri = $_SERVER['REQUEST_URI']; $query_strlen = strlen($_SERVER['QUERY_STRING']); if ($query_strlen) $request_uri = substr($request_uri, 0, -($query_strlen + 1)); switch ($request_uri) { case $SETURL: bf_setcookie(); break; case $CHKURL: bf_testcookie(); break; default: if ($_COOKIE['HUMAN'] == 'yes') bf_displayreload(); else bf_displayform(); } ?>