Search code examples
phpblockwebsite-hosting

How block site by region


Good afternoon! I would like to know how I can block my site in some regions by PHP. I do not want my site to run in all regions Can someone help me?


Solution

  • The best way to do this is to use a firewall. Another way is to use Apache. An easy way to do this is to use this link.

    With this tool you can select the countries you do not intend to serve, which gives you the default settings.

    Of course, I hope you do not intend to block your services to Iranians :)

    If you want to try blocking the city nonetheless, take a look at mod_security +GeoIP (assuming you're using Apache).

    Updated:

    you can to use IptoLocation Script(http://www.ip2location.com/) and then you can check the city or region after that Blocking a City or Region from website. You can query block information at http://location2ipaddress.com/ for example. If you want to use the .htaccess file to do this, then all you need is the ip range data - put this into the deny list and you're done.

    Furthermore you can use any geoIP API to query the location of the visitor. Just google geoIP API to see what's available. There are online solutions and downloadable databases as well.