Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Banning bad bots

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.

<?php
$i = getenv('REMOTE_ADDR');
$handle = fopen("../.htaccess", "a");
fwrite($handle, "Deny from $i\n");
fclose($handle);
echo "You've just got $i banned from this domain.  You are a very bad person.";
mail("webmaster@example.com", "Banned IP", "Deny from $i");
?>
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS