CloudFlare has a nice feature where they pass the country of the visitor in a HTTP header.

This can then be used by various modules, like the IP2Locale module http://drupal.org/project/ip2locale

To use the feature, and provide it to other modules, all you need is to add this bit at the end of cloudflare.module

// Extension for the backend of ip2locale.
function cloudflare_get_country(){
  return $_SERVER['HTTP_CF_IPCOUNTRY'];
}

Comments

Brian294’s picture

Issue summary: View changes
Status: Needs review » Postponed (maintainer needs more info)

Interesting idea. Though, I do not believe making this change alone will make it work with ip2locale. According to the module code, a module must be setup as a backend

/**
 * Get a list of supported backends for IP to Country lookups.
 *
 * @return
 *   An array containing the module names of backends.
 */
function _ip2locale_supported_backends() {
  $backends = array(
    'ip2cc' => 'ip2cc_get_country',
    'ip2country' => 'ip2country_get_country',
    'geoip' => 'geoip_country_code',
    'smart_ip' => 'smart_ip_get_location',
  );
  return $backends;
}

Perhaps I am missing it, but I don't see a general hook in ip2locale to check for hook_get_country, so there is no way to register my module implementation with their module.

rosk0’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)