How can I block an IP address?
You may want to block certain IP addresses so that they cannot access your website. You can do this quite easily with a PHP script or with a .htaccess file (Linux only). We also give an ASP example. Of course these are small, simple scripts; you can also find more advanced scripts online, free or paid. Just search for php/htaccess/asp (one of the three) and ip block script.
PHP EXAMPLE
In this PHP example you send the visitor to a non-existent page. You could also send them to another site such as Google, but that of course depends on your goal.
<?php
$deny = array("111.111.111", "222.222.222", "333.333.333");
if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
header("HTTP/1.0 404 Not Found"); // or send them to Google, for example: header("location: http://www.google.com/");
exit();
} ?>
.HTACCESS EXAMPLE
You can also block IP addresses in a .htaccess file (place it in the public_html directory, Linux hosting only):
<Limit GET>
order allow,deny
allow from all
deny from 123.456.789.0
deny from 123.4.5.
</Limit>
ASP EXAMPLE
An ASP (Windows hosting) example (remember to create the no_access.asp page, and put for example the text of a 404 page in it):
<%
Dim sBlockedIPsBlockedIP = Request.ServerVariables("REMOTE_ADDR")
'check if the IP is the one that is blocked
If sBlockedIP = "32.454.42.12" Then
'if IP address is banned then redirect to no_access.asp
Response.Redirect "no_access.asp"
End If
%>
