Ban and allow IP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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?  

Re: Ban and allow IP

John wrote:
Quoted text here. Click to load it

Yes it is :

if ($_SERVER['REMOTE_ADDR']  != '')

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

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

Order deny,allow
Deny from all
Allow from

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



Re: Ban and allow IP wrote:

Quoted text here. Click to load it

Default filename for this directory configuration file is .htaccess,

Kim André Akerø
(remove NOSPAM to contact me directly)

Re: Ban and allow IP

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

deny from

Hope you will understand this.


Site Timeline