Easily Geolocate your visitors using CloudFlare

Thu, 2013-04-11 14:59

I'm a huge fan of CloudFlare and with recent SpamHaus DDoS attack, they have increased their reputation in their service.

If you are using CloudFlare, and in need to detect the visitor's language, I have a good news for you.

CloudFlare automatically makes available some variables that you can access server-side.

<?php
  $country
= $_SERVER['HTTP_CF_IPCOUNTRY'];
?>

You will get the 2 letter short code of the country code, or XX if CloudFlare failed to geolocate the user (See the list of ISO country codes).