question on efficiency: IP blocking in .htaccess versus php

Discussion in 'Site & Server Administration' started by Neutron, Feb 29, 2008.

  1. #1
    I have a list of over 400,000 IP addresses I would like to detect when they try to access my site, and silently reroute them to another web page. Don't ask why. ;)

    Would it be faster (and with less strain on my server) to do it in

    1) php with something like this
    <?php
    $deny = array("111.111.111", "222.222.222", "333.333.333");
    if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
       header("location: http://www.google.com/");
       exit();
    } ?>
    Code (markup):
    2) or in .htaccess with mod_rewrite

    3) or maybe in my httpd.conf file?
     
    Neutron, Feb 29, 2008 IP
  2. agnivo007

    agnivo007 Peon

    Messages:
    4,290
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    0
    #2
    .htaccess is obviously faster; but large .htaccess files can hang up the server.

    If this is for blocking specific countries, try the apache mod_geoip :)
     
    agnivo007, Feb 29, 2008 IP
  3. maestria

    maestria Well-Known Member

    Messages:
    705
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    would be fast if you put it in httpd.conf, and would be a bit more fast if you put in .htaccess and less fast if you put in the php file.
    because thats the way the flow of control happens.
     
    maestria, Mar 1, 2008 IP
  4. RoscoeT

    RoscoeT Peon

    Messages:
    78
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If it's "your server" and it's Linux write a script with ipchains/iptables. keep the IPs in a DB.

    That would be the most effective.
     
    RoscoeT, Mar 1, 2008 IP