How to display information based on geo location using ip2cc
I developed IP to Country module for Drupal last year. The original purpose was to see who visited my site through Search Keywords module. Anyway, it is also possible to use ip2cc module for automatically display information based on geo location.
After installing ip2cc, you just need to either create a page with php or Front Page module with php.
$default_cc = "us";
$avail_cc = array("us","uk");
$cc = $default_cc;
$addr = $_SERVER['REMOTE_ADDR'];
$country = module_invoke('ip2cc','get_country',$addr);
if (isset($country)) {
$cc = strtolower($country->country_code);
if (!in_array($cc,$avail_cc)) {
$cc = $default_cc;
}
}
drupal_goto($cc);
?>
Using above php code, your visitors will be redirected to page us
or uk
according to their IP address.
Tags: drupal, ip2cc, ip to country, search keywords
- sugree's blog
- 2581 reads
Post new comment