PHP IP address based redirect example

3

This is a IP address redirect example.Check visitor IP address is exist in the IP address list/black list and if exist then visitor redirect to the another location using php.You can put your IP addresses list as line by line with single IP address or CIDR notation.Then check visitor IP address with list and redirect them.

Step-1

You can put IP addresses as follows in the text file named “ip-address.txt” file.

127.2.0.1/27
127.3.0.1/32
127.0.0.1

Step-2

Now get this IP addresses line by line.You can get more info about reading file line by line in my another post named “PHP read file line by line to an array“.

Step-3

Get visitor IP address.

Step-4

Then you need to pass visitor IP address and read IP addresses list as parameters to following function.It will return IP address is exist or not.

Step-5

Finally get response from above function and redirect them.

Putting all together

Check a particular network/mask combination

Note:

Download Blocking IP Address Example (2 KB)

Share.

About Author

Sumith Harshan is the Web Engineer Specializes in Java Script, JQuery, HTML4/5, CSS2/3, PHP, CodeIgniter, CakePHP, J2SE, J2EE, XML, Hacking & Security, Mobile Interface Developing, Magento, Wordpress, Joomla, Drupal,PHPBB,Facebook App Developing and Open cart...etc.