2.8.20. Determining the visitor's country in PHP

Country code options in .htaccess described here.

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 $_SERVER['HTTP_GEOIP_COUNTRY_CODE'].