2.8.20. Determining the visitor's country in PHP
Each site request contains a special header
HTTP_GEOIP_COUNTRY_CODEwhich contains the visitor's two-letter country code (ISO 3166). The country is determined based on the visitor's IP address as reported by MaxMind GeoLite.
You can get the two-letter country code in PHP from the server variable