Search code examples
phpip-addresscidr

What is the best and quickest way to block / allow only ranges IPS by CIDR (lock / permission ranges IPs of a country)


I need to give access permission to users only if they are from a certain country, I currently do this with PHP, I put all the IP ranges of the country in an array, use one check_cidr function to check if the IP is allowed or not, I also have the method of Allow / Deny in htaccess.

What is the fastest and optimized weight and way less cpu load on the server? There are some official and updated list of all the IP ranges of the countries?


Solution

  • Using the Allow and Deny is probably faster because it doesn't require running a script. The htaccess file will need to be read but as long as it's unchanged, nothing else needs to happen. It would work even faster if you put them in the server/vhost config instead of an htaccess file.

    As for allocation blocks, there's several places that you can google: