Hello Friends ,

If you are looking to block some of your visitors by their IP address here are the some way that might help you.

1. Using .htaccess

If you want to block IP address using .htaccess file than just copy the below code and paste it in to your .htaccess file. You just need to change the IP address that you want to block. Replace 120.120.120.120 with the IP address that you want to block.

order deny,allow
allow from all
deny from 120.120.120.120

If you want to block series of IP address than just copy the below code and paste it in to your .htaccess file. And replace your IP address series. As per example given deny from 120.120.120 means it blocks 120.120.120.0 , 120.120.120.1 , .. , 120.120.120.255 IP addresses (means total 256 IP addresses).

order deny,allow
allow from all
deny from 120.120.120.

In some cases if you want to block bunch of IP address than just copy the below code and paste it in to your .htaccess file. And replace your IP address bunch as per yours . As per example given deny from 120.120.*. means it blocks 120.120.*.0 , 120.120.*.1 , .. , 120.120.255.255 IP addresses (means total 256 * 256 = 65536 IP addresses).

order deny,allow
allow from all
deny from 120.120.*.


2 . Using php file

If you don’t have .htaccess file access and want to block IP address using .php file than just copy the below code and paste it in to your .php file. You just need to change the IP address that you want to block. Replace 120.120.120.120 , 120.120.120.121 , 120.120.120.122 with the IP addresses that you want to block. You can define as many IP address as you want to block in an array declared below.

<?php
$block = array(“120.120.120.120″, “120.120.120.121″, “120.120.120.122″);
if (in_array ($_SERVER['REMOTE_ADDR'], $block))
{
header(“location: http://www.yoursite.com/404.php?error=notallow”);
exit();
}
?>

If you want to generate  .htaccess file than click here .

Cheers !!

 

Related posts:

  1. Orkut Scrap tricks and tips – Add links , font colors , font family, images/photos , audio ,videos
  2. Speed up your blog with Asynchronous Tracking of Google Analytics
  3. Mysql Tutorial – Upload files to MYSQL database
  4. Mysql Tutorial – Download files from MYSQL database