How do I retrieve a visitor's country in my scripts?
What is IP geolocation?
IP geolocation reliably identifies a visitor's country from their public IP address. At Hodi, this service relies on data from ipinfo.io, a specialized provider whose databases are updated daily.
You can use this technology to personalize the user experience (adapting language, currency or offers to the visitor's country), or for compliance purposes (restricting access to certain content by country).
Which variables are available?
Our servers automatically add variables to the web server environment:
Variable | Content | Example |
|---|---|---|
| Country code in ISO 3166-1 alpha-2 format (2 uppercase letters) |
|
| Continent name (in English) |
|
| Autonomous system (AS) number of the visitor's network operator |
|
| Network operator name |
|
| Network operator domain |
How do I use them?
In PHP:
$country = $_SERVER['IPINFO_COUNTRY_CODE'] ?? '';In an .htaccess file, for example to allow only France and Réunion:
RewriteEngine On
RewriteCond %{ENV:IPINFO_COUNTRY_CODE} !^(FR|RE)$
RewriteRule .* - [F,L]In Node.js, Apache environment variables are not passed directly to your application. First convert them to an HTTP header in your .htaccess:
RequestHeader set X-Country-Code "%{IPINFO_COUNTRY_CODE}e"then read it in your application:
const country = req.get('X-Country-Code');
Is the data reliable?
The ipinfo.io database is updated daily on our servers. Country-level accuracy is very high. However, as with any IP-based method, some edge cases (VPN, proxy, shared IP) can skew detection: do not use it as your only security mechanism.
Updated on: 12/08/2026
Thank you!