Currently an external service is queried once per session to determine the user's IP address.

TODO: provide local solution to avoid this external dependency.

Possibility: build on ip2cc http://drupal.org/node/45806

However, that module looks to need some refactoring. I opened two issues: #309952: Pull JSON functionality into a separate module, #309947: Pull node handling into a separate module.

Comments

recidive’s picture

Another possibility is to build on geouser module (http://drupal.org/project/geouser) that's based on data from http://www.maxmind.com/ and have up to city granularity. Also this provides coordinates, which can help if we e.g. need automatic time zones discovering. I don't know the status of that module and the accuracy of maxmind data compared to ip2cc, though.

nedjo’s picture

Title: Local handling of ip2cc determination » More robust, flexible handling of ip2cc determination

We should support multiple external solutions for IP to location mapping, while probably having a simple fallback like the one already implemented.

Existing Drupal modules handling ip2cc or similar functionality generally are uneven, are tied to their particular proprietary third party solutions, lump in a lot of additional functionality, and produce data in very different ways.

As in many other cases, e.g. wysiwyg, there's a need here for a generic API that can be used for various third party solutions, providing data in an established format.

nedjo’s picture

Version: » 6.x-1.x-dev
Priority: Normal » Critical

This needs to be done. For high traffic sites we can't rely on an external service.

Proposed implementation:

1. Introduce a hook_country_code_handler through which modules can register their handlers for country code determination.

2. Implement this hook in country_code using the existing call.


function country_code_get_country_code_hostip($ip_address) {
  return strtolower(file_get_contents('http://api.hostip.info/country.php?ip=' . $ip_address));
}

function country_code_country_code_handler() {
  return array(
    array(
      'name' => t('hostip.info'),
      'country_code_get_country_code_hostip',
    ),
  );
}

3. Introduce an admin setting to select which handler to use.

4. Write implementations for other, more robust handlers.

nedjo’s picture

Assigned: Unassigned » nedjo

I'm going to implement this approach.

nedjo’s picture

Assigned: nedjo » Unassigned
Status: Active » Fixed

Introduced this hook with the existing hostip implementation.

Added a config option that shows up only if there is more than one hanlder available.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

zidong.c’s picture

Thank you for your attention for GeoUser module (http://drupal.org/project/geouser), I am the author of this module.
This module is based on an IP database called GeoLiteCity, which as far as I know is most accurate free/open source IP database available, they also provide a commercial one which is more accurate.
I am currently working on providing an easy-to-use, and easy-to-understand API for other Drupal module to retrieve Geographic information based on user's IP address.

The GeoUser module is on Beta status now, you can check out if you're interested.

Zidong