1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to block specific IP address?

Discussion in 'Apache' started by panfor, May 24, 2007.

  1. #1
    I found an user which visits my site to quickly (his HTTP_USER_AGENT is empty). I would like to ban his ip address to prevent the access to the server.

    How can i do that? I am using PHP with mySql and Apache.
     
    panfor, May 24, 2007 IP
  2. erotomania

    erotomania Banned

    Messages:
    291
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to get or gather the IP address of your visitors to get the Ip:

    <?php $ip = $_SERVER['REMOTE_ADDR'];
    Code (markup):
    if you still don't know what to do, here is the complete code that i always use;

    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    $ban = array('333.333.333.333','68.225.34.86');
    $count = count($ban);
    for ($i=0; $i<$count; $i++) {
    if($ip == $ban[$i]) { die("I'm sorry, you've been banned. $ip"); }
    }
    ?>
    Code (markup):

    notice 61.9.18.62. this is the IP to be banned.
     
    erotomania, May 24, 2007 IP
  3. panfor

    panfor Peon

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, it works for me.
    But... is there another method using .htaccess?
     
    panfor, May 24, 2007 IP
  4. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Yup, like this:

    deny from 12.345.78.9

    etc...
     
    wing, May 24, 2007 IP
  5. panfor

    panfor Peon

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks for informations, I have found similar thread. :D
     
    panfor, May 24, 2007 IP
  6. inworx

    inworx Peon

    Messages:
    4,860
    Likes Received:
    201
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Its better using .htaccess since it bans from the whole site.
     
    inworx, May 26, 2007 IP
  7. grandy

    grandy Banned

    Messages:
    239
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    As there are loads of other suggestion thats why i think this suggestion would be good for you. If you have the root access then you can go for it.

    Use Iptables to block an IP with the following command:

    Regards
     
    grandy, Jun 5, 2007 IP