How to block IP countries with php?

by 5 replies
6
I try to do following Blocking Website Access by Country with PHP | Azulia Designs but when I check my site with my country ip it still access and error occur because it not found .php in ip_files folder.

So, I want to know other methods that easy and works fine.

Thank you very much.
#programming #block #countries #php
  • Well try to find an API, you can find a public one easily that can tell you what country is of IP and then you can write php code to let allow to redirect it somewhere. Google for public api's to get country by IP
  • I do it via htaccess instead of php. If you can't get the php to work it's an option for you.
  • You can do it usign htaccess or you should have a IP to country database and then you can restrict using php script
  • Note that if anyone is using proxy it can avoid IP filtering.
  • You can use xforwarded for header info:

    if($_SERVER["HTTP_X_FORWARDED_FOR"] != ""){ $IP = $_SERVER["HTTP_X_FORWARDED_FOR"]; $proxy = $_SERVER["REMOTE_ADDR"]; $host = @gethostbyaddr($_SERVER["HTTP_X_FORWARDED_FOR"]); }else{ $IP = $_SERVER["REMOTE_ADDR"]; $proxy = "No proxy detected"; $host = @gethostbyaddr($_SERVER["REMOTE_ADDR"]); }

Next Topics on Trending Feed

  • 6

    I try to do following Blocking Website Access by Country with PHP | Azulia Designs but when I check my site with my country ip it still access and error occur because it not found .php in ip_files folder. So, I want to know other methods that easy and works fine.