PHP IP address based redirect example

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.


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


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“.


Get visitor IP address.


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.


Finally get response from above function and redirect them.

Putting all together

Check a particular network/mask combination


Download Blocking IP Address Example (2 KB)