Ban and allow IP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    Ban and allow IP

    Hello, is it possible with PHP to ban a certain range of IPs but at the same
    time allow access from one specific IP from this range? Code example?


  • sam.partington@gmail.com

    #2
    Re: Ban and allow IP


    John wrote:[color=blue]
    > Hello, is it possible with PHP to ban a certain range of IPs but at the same
    > time allow access from one specific IP from this range? Code example?[/color]

    Yes it is :

    if ($_SERVER['REMOTE_ADDR'] != '123.45.67.89')
    {
    exit;
    }

    But its not the best way. The better way would be to do it using your
    web server's settings. In Apache you would do something like this in
    httpd.conf :

    <Directory /usr/local/cgi-bin/>
    Order deny,allow
    Deny from all
    Allow from 123.45.67.89
    </Directory>

    Or in a file called .htconfig in the directory in which you wish to
    deny access :

    Order deny,allow
    Deny from all
    Allow from 123.45.67.89

    (I think, I've never used Deny, Allow in .htconfig myself check out the
    docs for your webserver)

    HTH

    Sam

    Comment

    • Kim André Akerø

      #3
      Re: Ban and allow IP

      sam.partington@ gmail.com wrote:
      [color=blue]
      >
      > John wrote:[color=green]
      > > Hello, is it possible with PHP to ban a certain range of IPs but at
      > > the same time allow access from one specific IP from this range?
      > > Code example?[/color]
      >
      > Yes it is :
      >
      > if ($_SERVER['REMOTE_ADDR'] != '123.45.67.89')
      > {
      > exit;
      > }
      >
      > But its not the best way. The better way would be to do it using your
      > web server's settings. In Apache you would do something like this in
      > httpd.conf :
      >
      > <Directory /usr/local/cgi-bin/>
      > Order deny,allow
      > Deny from all
      > Allow from 123.45.67.89
      > </Directory>
      >
      > Or in a file called .htconfig in the directory in which you wish to
      > deny access :
      >
      > Order deny,allow
      > Deny from all
      > Allow from 123.45.67.89
      >
      > (I think, I've never used Deny, Allow in .htconfig myself check out
      > the docs for your webserver)[/color]

      Default filename for this directory configuration file is .htaccess,
      though.

      --
      Kim André Akerø
      - kimandre@NOSPAM betadome.com
      (remove NOSPAM to contact me directly)

      Comment

      • Rupom

        #4
        Re: Ban and allow IP

        Lets say the IP you want to ban is 192.168.1.10. The following htaccess
        code will ban this IP:

        deny from 192.168.1.10

        Hope you will understand this.

        Regards,
        Rupom


        Comment

        Working...