Ban people by IP address

Banning people from your website results in a loss of traffic but there are certain situations where this is necessary. For example, if you run a forum on your website and someone is causing trouble all the time or someone is using an automated program to fill in your contact form that results in you receiving annoying spam mail.

Ban through .htaccess

You can ban single IP's or IP address ranges.

Ban setup

Begin with this code in your .htaccess file:
<Limit GET POST> order allow,deny #BAN CODE will go here allow from all </Limit>

Banning single IP addresses

For each IP address you want to ban, put deny from followed by the IP address.

Begin with this code in your .htaccess file:
<Limit GET POST> order allow,deny deny from 192.168.1.12 deny from 10.1.1.99 allow from all </Limit>

Banning IP ranges

Works the same way as banning individual IP addresses, but put the range instead of the Individual IP address.

IP Range examples:
10. (all the IP's that start with 10. (10.1.1.1 - 10.255.255.255) 34.14. (all the IP's that start with 34.14 (34.14.1.1 - 34.14.255.255) 100.120.15. (all the IP's that start with 100.120.15 (100.120.15.1 - 100.120.15.255)
IP Range banning example:
<Limit GET POST> order allow,deny deny from 10. deny from 34.14. deny from 100.120.15. allow from all </Limit>

Banning redirect

Add this line to your .htaccess file to redirect banned people elsewhere:
ErrorDocument 403 http://www.site.com/page.html

where http://www.site.com/page.html is the URL they will be redirected to.

NOTE: To ban people from an entire Internet Provider find out the IP range that that Internet provider uses and include it in your .htaccess file.

NOTE: Be careful with IP address banning. Make sure you ban only the bad guys and not legitimate traffic!

© Copyright 2013-2014 Landofcode.com
Terms of use | Privacy policy | Copyright information