Mondoze Knowledge Base

Search our articles or browse by category below

What does Cloudflare IP Geolocation do?

Last modified: October 11, 2022
You are here:
Estimated reading time: < 1 min

What Does Cloudflare IP Geolocation Do?

You can enable IP Geolocation to have Cloudflare geolocate visitors to your website and pass the country code to you in ISO 3166-1 Alpha 2 format. 

You will find the IP Geolocation option under the Network app in the Cloudflare dashboard.

The option for IP geolocation will be found near the bottom of the page:

Once enabled, Cloudflare adds a header called “CF-IPCountry” to all requests we make to your website. Here are a couple of examples of how to access/store this value:

$country_code = $_SERVER["HTTP_CF_IPCOUNTRY"]; // to access in PHP
$country_code = $ENV{"HTTP_CF_IPCOUNTRY"}; # to access in Perl

Cloudflare includes this information for both IPv4 and IPv6 addresses. Currently, the IPv4 information is more robust, but we expect the IPv6 data to improve rapidly.

If it is XX means there is no country data. T1 is a non-standard country code used for the Tor network.

Was this article helpful?
Dislike 0
Views: 195