<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: bots code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 01:01:11 GMT</pubDate>
    <description>DZone Snippets: bots code</description>
    <item>
      <title>Banning bad bots</title>
      <link>http://snippets.dzone.com/posts/show/1935</link>
      <description>The following code is the contents of /banme/index.php.  This file is linked to from my main website but invisible to web browsers and disallowed in robots.txt.  Therefore, only bad bots will ever follow this link and when they do so they will get banned in .htaccess and their ip address will be emailed to webmaster@example.com.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$i = getenv('REMOTE_ADDR');&lt;br /&gt;$handle = fopen("../.htaccess", "a");&lt;br /&gt;fwrite($handle, "Deny from $i\n");&lt;br /&gt;fclose($handle);&lt;br /&gt;echo "You've just got $i banned from this domain.  You are a very bad person.";&lt;br /&gt;mail("webmaster@example.com", "Banned IP", "Deny from $i");&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 18 Apr 2006 15:49:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1935</guid>
      <author>lordrich ()</author>
    </item>
  </channel>
</rss>
