How to block someones IP address?

by 29 comments
HI,

I have been getting junk emails from automated bots on my website's form. I have installed a captcha and that worked for a while but a few days ago I started getting those annoying emails again.

I have the senders IP address. Is there a way to block the spammers IP address? My host is Yahoo and Yahoo does not support .htaccess.
(Trying to change hosting soon)

Is there a way to block the IP without using .htaccess?
#programming #address #block #email #ipaddress #someones #spam

  • Profile picture of the author Nathan K
    Add this line on top of your header file, and enter the ipaddress.

    <?php
    $deny = array("000.000.000","000.000.001");
    if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
    header("location: http://www.google.com/");
    exit();
    }
    ?>
  • Profile picture of the author Kingfish85
    Originally Posted by Ani86 View Post

    HI,

    I have been getting junk emails from automated bots on my website's form. I have installed a captcha and that worked for a while but a few days ago I started getting those annoying emails again.

    I have the senders IP address. Is there a way to block the spammers IP address? My host is Yahoo and Yahoo does not support .htaccess.
    (Trying to change hosting soon)

    Is there a way to block the IP without using .htaccess?
    1. The IP's will most likely always be different.

    2. Yahoo doesn't support htaccess......yea, it's time to find a "real" web host.
  • Profile picture of the author Ani86
    They say that they support htaccess.txt not .htaccess

    you think this will work if i use htaccess.txt ?
  • Profile picture of the author sonzoy
    if your host is not supporting .htaccess then use Nathan K PHP script otherwise changing the host will be always an advantage ....
  • Profile picture of the author chrislim2888
    Personally, I'm not recommend the blocking at page level. Therefore, if possible change the hosting will be an option to consider, for long term solution.
  • Profile picture of the author Ani86
    I called yahoo again they said .htaccess is same as their htacess.txt they dont put the (.) in the beginning but instead they use .txt the tech guy said its the same thing.

    Now how can I block the IP address in the htaccess file. does anyone know how to write the code for that?

    and I'd like to learn more about Nathan K's code. anyone got a link that explains the code?

    I wrote this code but not sure if its correct or not

    <Limit GET>
    order allow,deny
    deny from 10.20.30
    deny from 192.168.207.154
    allow from all
    </Limit>
  • Profile picture of the author kyoo
    Originally Posted by Ani86 View Post

    and I'd like to learn more about Nathan K's code. anyone got a link that explains the code?
    Nathan's Code will only work on a PHP page, not a static HTML page.

    It Basically runs through a list of ip addresses (In the $deny variable) and if the browsing IP matches one of them, it redirects them somewhere else by writing a location header.

    Your apache code should work, but I always place the deny after the allows, because I'm not sure if it gets applied in order.

    <Limit GET>
    order allow,deny
    allow from all
    deny from 10.20.30
    deny from 192.168.207.154
    </Limit>

    [/QUOTE]
  • Profile picture of the author Ani86
    So if I use this code

    <?php
    $deny = array("000.000.000","000.000.001");
    if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
    header("location: http://www.google.com/");
    exit();
    }
    ?>

    All I have to do is put the IP address in place of 000.000.000s and put the code in the beginning of the contact.php file? Is that all?
  • Profile picture of the author kyoo
    That should do it, although I haven't tested this snippet of code, there may be typos etc. Nathan K probably pulled it from someplace where it was working.
  • Profile picture of the author webzie
    Blocking him from your website would be hard, because all he needs to do is use a proxy to disguise his IP.. But you can block it from control panel of your hosting
  • Profile picture of the author CrazyStyle
    Code:
    <?php
    if($_SERVER['REMOTE_ADDR'] == 'xx.xx.xx.xxx'){
            die("Go to hell.");
    }
    ?>
  • Profile picture of the author webisland
    You can write rewrite rules or you can write php or any serverside script to block ip address or country
  • Profile picture of the author Ani86
    Originally Posted by webzie View Post

    Blocking him from your website would be hard, because all he needs to do is use a proxy to disguise his IP.. But you can block it from control panel of your hosting
    How do i block from hosting? my hosting is 1and1
  • Profile picture of the author WriteArm
    Ani 86 : Have you tried just using IP deny in the cpanel?
  • Profile picture of the author DAVE49
    Here you can find all information about your IP
  • Profile picture of the author project1010
    If you have programmatic control over your website, then you can block an IP address. For example, in VBScript for ASP,
    <%
    if ( request.servervariables ("remote_host") = "XXX.XXX.XXX.XXX") then response.redirect "http://www.google.com"
    %>

    where XXX.XXX.XXX.XXX is his IP address.
  • Profile picture of the author Kingfish85
    junk emails from automated bots

    This means the IP addressed CHANGE....they CHANGE = not the same.

    Adding code to the htaccess is NOT going to do anything here....do you people even read the thread before commenting with useless rpelies?!

    You need to use something like CloudFlare or a host that has a better firewall or WAF.
  • Profile picture of the author buysellbrowse
    Since you have a website form visible from anywhere in the world, blocking a few IPs will not help much. You need a better captcha system that hasn't been broken yet, preferably something that requires the user to understand instructions, then move an object with the mouse to complete a task. Eye-hand coordination is something a computer cannot do (yet).
  • Profile picture of the author Roy Jones
    You can block an IP Address using IPSec

    STEP 1:
    Click on Start menu, then click on Run

    STEP 2:
    Type " secpol.msc" and Click OK

    STEP 3:
    When the Local Security Settings console opens, Click on "IP security policies on Local computer"
  • Profile picture of the author shahriyar
    I receive a lot of spam every day on my sites, blocking IPs is a solution but not a good one. Because spam will come all kinds of different IPs, they never stay the same.

    You should focus on improving security on your forms. Have you tried using reCaptcha? http://www.google.com/recaptcha

Next Topics on Trending Feed