> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.hodi.host/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# 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](https://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 |
| ---- |
| `IPINFO_COUNTRY_CODE` | Country code in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) format (2 uppercase letters) | `CI` |
| `IPINFO_CONTINENT` | Continent name (in English) | `Africa` |
| `IPINFO_AS_NUMBER` | Autonomous system (AS) number of the visitor's network operator | `AS64496` |
| `IPINFO_AS_NAME` | Network operator name | `ACME Telecom Ltd` |
| `IPINFO_AS_DOMAIN` | Network operator domain | example.com |

## How do I use them?

**In PHP:**

```php
$country = $_SERVER['IPINFO_COUNTRY_CODE'] ?? '';
```

**In an .htaccess file**, for example to allow only France and Réunion:

```apache
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`:

```apache
RequestHeader set X-Country-Code "%{IPINFO_COUNTRY_CODE}e"
```

then read it in your application:

```javascript
const country = req.get('X-Country-Code');
```

## Is the data reliable?

The [ipinfo.io](https://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.