I read "Blocking Badly Behaved Bots" and its predecessor, and I'd like to ask a relatively simple question:
Assuming I already have the bad IP to ban (let's call it $ip), how would I write the IP to the appropriate line in .htaccess, and safely?
I'd like to use a relatively simple script like this one:
<?php
$file = $_SERVER['DOCUMENT_ROOT'] .'/.htaccess';
$fp = fopen($file, 'a');
fwrite($fp, "Deny from".$ip."\n");
fclose($fp);
?>
But again, I'm not sure how safe this is, and it doesn't write the IP to the correct line. Any suggestions? I know the other anti-bot scripts do this, but it is very (needlessly?) complicated and I have not been able to block the IP in the right line. Please help out a newbie trying to defend his sites vulnerable forms! Thanks.