Forum Moderators: goodroi
On Apache, use mod_access or mod_rewrite to control access by IP address or address range. On IIS, you may be able to use ISAPI Rewrite. Or, if you use PHP headers, you could include code in your header to deny access to address ranges corresponding to certain countries.
However, there is more bad news, and that is that IP address ranges are allocated on request, and not allocated based on country. So you will either have to deny a fairly long list of IP address ranges, or deny them on an as-needed basis.
Another alternative is to use geoIP services to look up the country based on the IP address. These services build and maintain the huge databases needed to correlate IP addresses with countries, while giving you a simple method to query their database and receive the corresponding country code.
Try some searches here and abroad on the terms above; Each subject is fairly deep, with many options and sub-options, and beyond the scope of a reasonable-length forum post.
Jim