tags:

views:

96

answers:

4

From a performance only view, which would be the best way to block 30 IP addresses?

A) .htaccess file

or

B) PHP code in the file

+8  A: 

If you are administrator of your server, I would use none of those, and would ban the IPs at the firewall level -- this way, nor Apache nor Apache+PHP will have to work.

If you're not admin ; well, .htaccess means only Apache, and no PHP to load/compile/execute ; I'm guessing Apache alone (i.e. .htaccess) should require less resources than Apache+PHP.


Another way of seing things is maintenance : if you need to add/delete IPs addresses from that list, what would the easiest way be ?
(In that case, I would generally bet for some PHP code...)

Pascal MARTIN
Thanks, I am curious, would it be possible to write a PHP script that could add/remove IP's being blocked at the server firewall level?
jasondavis
I suppose it would be possible -- provided the user than runs the PHP scripts has the privileges required to do that kind of action ;; and not sure the user that runs Apache has that kind of power... *(I have to admit I've never tried, actually)*
Pascal MARTIN
A: 

I agree with Pascal's answer. But the PHP code is:

$banned = array('129.168.1.1');
if(in_array($_SERVER['REMOTE_ADDR'], $banned))
{
    die();
}

And the .htaccess is:

order allow,deny
deny from 192.168.1.1
allow from all

Just for the record.

Chacha102
Yeah I use something like that now but I am thinking of doing it at a server level before PHP hopefully –
jasondavis
I would check the X_HTTP_FORWARDED_FOR header too if using PHP.
hobodave
Yeah, there would probably be a little more processing, but the basic elements are there.
Chacha102
+1  A: 

Why not block them at the hardware level (router, load balancer, firewall, etc)? - If its only a block of 30 and you don't need to update them often.

Mr-sk
I will deffinately look into this, looking at all option right now
jasondavis
+1  A: 

Hardware

or

Hardware + OS

or

Hardware + OS + Apache

or

Hardware + OS + Apache + PHP

Understanding the stacks should help indicate which will be the fastest.

Mike B