Forum Moderators: phranque

Message Too Old, No Replies

Writing Blocked IPs in .htaccess

The Safest, Simplest Method?

         

inuwolf

5:33 am on Feb 23, 2006 (gmt 0)

10+ Year Member



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.

inuwolf

5:08 pm on Feb 23, 2006 (gmt 0)

10+ Year Member



Nevermind. Probably a better question for the PHP forum.

jdMorgan

8:42 pm on Feb 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Answered here [webmasterworld.com]