How to detect the country of the website visitor in Drupal

<p>We want to detect the country of a website visitor in Drupal in order to redirect the user automatically to a specific page according to its country (or to compute the correct lanuage&nbsp;or currency for the current user)</p>
2 answers

geoip php modules

geopip provides some php modules to use, which could easily be turned into a drupal module http://www.maxmind.com/app/php.

Taggings:

Detect the country of the website visitor in Drupal

To solve the chanllenge you have to:

  1. Download the Drupal module ip2Country from http://drupal.org/project/ip2country
  2. Put this module in the /modules directory and activiate it from the Drupal control panel.
  3. In your custom PHP Code, you can now call the function:
  •  function uc_ip2country_get_country($ip_address)...where  the parameter $ip_address should be the IP of the current user which can be acquired using:
    • $ip_address = $_SERVER['REMOTE_ADDR']...This function returns the unique country code for the current website visitor.

Taggings: