How to retrieve the visitor's country with MaxMind?
What is MaxMind?
MaxMind is a company specializing in IP address geolocation ("GeoIP"). Using its databases, it is possible to reliably identify the country of origin of an Internet visitor based on their public IP address.
At Hodi, you can use this technology to personalize the user experience (for example, adapting the language, currency, or offers based on the visitor's country), or for compliance purposes (for example, restricting access to content by country).
How does it work on Hodi servers?
Our servers have the mod_maxminddb module integrated into Apache. This module reads the MaxMind database and automatically adds variables available in the web server environment.
The most important one for country identification is: MMDB_COUNTRY_CODE. This variable contains the ISO 3166-1 alpha-2 country code of the visitor (2 uppercase letters).
Here are some usage examples:
- In PHP, you can use the variable
$_SERVER['MMDB_COUNTRY_CODE'] - In Node.JS, you can use the function
req.get('MMDB_COUNTRY_CODE') - In a .htaccess, you can use this code to allow only France and Reunion Island for example:
` RewriteCond %{ENV:MMDB_COUNTRY_CODE} !^(FR|RE)$
RewriteRule .* - [F,L]`
Is MaxMind data reliable?
MaxMind databases are updated weekly. They offer generally very high accuracy (around 99.8%). However, as with any IP-based method, certain edge cases (VPN, proxy, shared IP) can skew the detection.
Updated on: 14/02/2026
Thank you!