geoPlugin module provides an API for integration with geoplugin.com, a free resource to provide geolocation technology to your site.

Installation:

  • Install and enable the module
  • If you want to use Javascript to access the geolocation data, go to admin/config/services/geoplugin page and enable the according checkbox.
  • If you want to use this module via PHP call, no additional setup is required.

Examples of usage:

You can use this module in two ways: via JavaScript call or via PHP call.

Javascript:

var geoplugin = jQuery.cookie('geoplugin');
if (geoplugin && geoplugin.hasOwnProperty('geoplugin_city')) {
  console.log("You are in " + geoplugin.geoplugin_city);
}

PHP:

if (module_exists('geoplugin')) {
  $geoplugin = geoplugin_locate();
  if (isset($geoplugin) && $geoplugin->city != '') {
    echo "You are in " . $geoplugin->city;
  }
}

The external API request is executed only once per visitor, and the response is stored in a a PHP session or (if using JavaScript) a cookie. The JavaScript method has the advantage of being compatible with any server-side caching mechanism your site may be using.

The data structure of the geoplugin javascript object:


Screenshot

The data structure of the geoplugin PHP object:

geoPlugin Object
(
    [host] => http://www.geoplugin.net/php.gp?ip={IP}&base_currency={CURRENCY}
    [currency] => USD
    [ip] => 92.20.44.88
    [city] => London
    [region] => London
    [areaCode] => 0
    [dmaCode] => 0
    [countryCode] => GB
    [countryName] => United Kingdom
    [continentCode] => EU
    [latitude] => 51.469501
    [longitude] => -0.0558
    [currencyCode] => GBP
    [currencySymbol] => £
    [currencyConverter] => 0.6714
)

Credits


Project information

Releases