Block user IP with .htaccess or PHP?

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

A) .htaccess file

or

B) php code in file

+5
source share
5 answers

If you are the administrator of your server, I would not use any of them and prohibit IP addresses at the firewall level - thus, Apache or Apache + PHP will not have to work.

If you are not an admin; well, it .htaccessmeans only Apache, and PHP does not load / compile / execute; I assume that only Apache (i.e. .htaccess) should require less resources than Apache + PHP.


: / IP- , ?
( PHP-...)

+9

. PHP:

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

.htaccess:

order allow,deny
deny from 192.168.1.1
allow from all

.

+3

Hardware

Hardware + OS

Hardware + OS + Apache

Hardware + OS + Apache + PHP

, .

+3

(, , ..)? - 30, .

+1

@MikeB . , PHP .htaccess , , honeypots IP-. :

login.php

if ($login_tries > 3) {
    touch('deny/' . $_SERVER['REMOT_ADDR']);
}

.htaccess

# check if ip has been banned
RewriteCond /usr/www/{YOUR_PATH}/deny/%{REMOTE_ADDR} -f
RewriteRule . - [F]

, , - captcha.

0
source

All Articles