Articles on: 🌍 Web Hosting
This article is also available in:

How do I retrieve the visitor's country with MaxMind?

What is MaxMind?

MaxMind is a company specializing in IP address geolocation ("GeoIP"). Thanks to its databases, it's possible to reliably identify the country of origin of an internet visitor from their public IP address.


At Hodi, you can use this technology to customize 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 this work on Hodi servers?

Our servers have the mod_maxminddb module, built 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 code of the visitor's country (2 uppercase letters).


Here are a few 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 an .htaccess file, you can use this code to allow, for example, only France and Réunion:

RewriteCond %{ENV:MMDB_COUNTRY_CODE} !^(FR|RE)$
RewriteRule .* - [F,L]


Is MaxMind's data reliable?

MaxMind's databases are updated every week. They generally offer very high accuracy (around 99.8%). However, as with any IP-based method, certain edge cases (VPN, proxy, shared IP) can throw off the detection.

Updated on: 17/07/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!