geoPlugin Home

How to plugin geoPlugin to your pages



Using geoPlugin directly from your pages, requires a javascript call1) to geoPlugin.
This can be done in 1 of 3 ways.

Geo-localized javascript only



<script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>



For more information on how to use this output, see the Quickstart section on How To geo-localize your visitors.
To see the javascript that geoPlugin outputs, view the HTML source of this page

How to geo-localize your visitors

2)

Enable the javascript code between the <head></head> tags of your pages:


<script language="JavaScript" src="http://www.geoplugin.net/javascript.gp" type="text/javascript"></script>


Once added, you will have geo-localized javascript functions available to your entire page.

These functions are as follows:

geoplugin_city()


geoplugin_region()

geoplugin_areaCode()

geoplugin_dmaCode()

geoplugin_countryCode()

geoplugin_countryName()

geoplugin_continentCode()

geoplugin_latitude()

geoplugin_longitude()

geoplugin_currencyCode()

geoplugin_currencySymbol()

geoplugin_currencyConverter()
    function geoplugin_currencyConverter(amt, symbol) { 
    	 var converted = amt * 0
    	 if (symbol == false) { return Math.round(converted * 100)/100; } 
    	 else { return '' + Math.round(converted * 100)/100; } 
     }


You can call any of these javascript functions in your scripts to output the relevant geo-localized information about your visitor.


geoPlugin Web Service interface



Sometimes you need more flexibility in your scripts and want to localize your visitor on your server backend script rather than on the web page frontend output. geoPlugin allows you to do this3) without the hassle of installing complex and large databases, by using one of the geoPlugin Web Services.

PHP service

The PHP service is the most popular service and will return a PHP serialized array of all the information of your visitor. Described in detail here, and a quick quide is given below.

Call this service in your script using


http://www.geoplugin.net/php.gp?ip=xx.xx.xx.xx


Of course, substitute the xx's with your visitor's IP number.

As an example, the following PHP snippet

 
echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])));


will output

array (
  'geoplugin_request' => '54.166.234.171',
  'geoplugin_status' => 206,
  'geoplugin_delay' => '1ms',
  'geoplugin_credit' => 'Some of the returned data includes GeoLite2 data created by MaxMind, available from https://www.maxmind.com.',
  'geoplugin_city' => '',
  'geoplugin_region' => 'Virginia',
  'geoplugin_regionCode' => 'VA',
  'geoplugin_regionName' => 'Virginia',
  'geoplugin_areaCode' => '',
  'geoplugin_dmaCode' => '',
  'geoplugin_countryCode' => 'US',
  'geoplugin_countryName' => 'United States',
  'geoplugin_inEU' => 0,
  'geoplugin_euVATrate' => false,
  'geoplugin_continentCode' => 'NA',
  'geoplugin_continentName' => 'North America',
  'geoplugin_latitude' => '38.6583',
  'geoplugin_longitude' => '-77.2481',
  'geoplugin_locationAccuracyRadius' => '1000',
  'geoplugin_timezone' => 'America/New_York',
  'geoplugin_currencyCode' => 'USD',
  'geoplugin_currencySymbol' => '$',
  'geoplugin_currencySymbol_UTF8' => '$',
  'geoplugin_currencyConverter' => '0',
)



Alternatively, simplify things using the free PHP Class


JSON service

More flexibile that Javascript, JSON can be used for more server-side processing, so we built a JSON webservice interface to geolocate your visitors.
Described in detail here, and a quick quide is given below.

Call the JSON service in your script using


http://www.geoplugin.net/json.gp?ip=xx.xx.xx.xx

Again, substitute the xx's with your visitor's IP number.

Example output of a JSON query for your IP address (54.166.234.171) is:

{
	
  "geoplugin_request":"54.166.234.171",
	
  "geoplugin_status":206,
  "geoplugin_delay":"2ms",
	
  "geoplugin_credit":"Some of the returned data includes GeoLite2 data created by MaxMind, available from https:\/\/www.maxmind.com<\/a>.",
	
  "geoplugin_city":"",
	
  "geoplugin_region":"Virginia",
	
  "geoplugin_regionCode":"VA",
	
  "geoplugin_regionName":"Virginia",
	
  "geoplugin_areaCode":"",
	
  "geoplugin_dmaCode":"",
	
  "geoplugin_countryCode":"US",
	
  "geoplugin_countryName":"United States",
	
  "geoplugin_inEU":0,
  "geoplugin_euVATrate":false,
  "geoplugin_continentCode":"NA",
	
  "geoplugin_continentName":"North America",
	
  "geoplugin_latitude":"38.6583",
	
  "geoplugin_longitude":"-77.2481",
	
  "geoplugin_locationAccuracyRadius":"1000",
	
  "geoplugin_timezone":"America\/New_York",
	
  "geoplugin_currencyCode":"USD",
	
  "geoplugin_currencySymbol":"$",
	
  "geoplugin_currencySymbol_UTF8":"$",
	
  "geoplugin_currencyConverter":0

}



XML service

XML is a versatile language, so we've added an XML interface too. Described in detail here, and a quick quide is given below.

Call the XML service in your script using


http://www.geoplugin.net/xml.gp?ip=xx.xx.xx.xx

Again, substitute the xx's with your visitor's IP number.

Example output of a XML query for your IP address (54.166.234.171) is:

<?xml version="1.0" encoding="UTF-8"?>
<geoPlugin>
	<geoplugin_request>54.166.234.171</geoplugin_request>
	<geoplugin_status>206</geoplugin_status>
	<geoplugin_delay>1ms</geoplugin_delay>
	<geoplugin_credit>Some of the returned data includes GeoLite2 data created by MaxMind, available from <a href='https://www.maxmind.com'>https://www.maxmind.com</a>.</geoplugin_credit>
	<geoplugin_city></geoplugin_city>
	<geoplugin_region>Virginia</geoplugin_region>
	<geoplugin_regionCode>VA</geoplugin_regionCode>
	<geoplugin_regionName>Virginia</geoplugin_regionName>
	<geoplugin_areaCode></geoplugin_areaCode>
	<geoplugin_dmaCode></geoplugin_dmaCode>
	<geoplugin_countryCode>US</geoplugin_countryCode>
	<geoplugin_countryName>United States</geoplugin_countryName>
	<geoplugin_inEU>0</geoplugin_inEU>
	<geoplugin_euVATrate></geoplugin_euVATrate>
	<geoplugin_continentCode>NA</geoplugin_continentCode>
	<geoplugin_continentName>North America</geoplugin_continentName>
	<geoplugin_latitude>38.6583</geoplugin_latitude>
	<geoplugin_longitude>-77.2481</geoplugin_longitude>
	<geoplugin_locationAccuracyRadius>1000</geoplugin_locationAccuracyRadius>
	<geoplugin_timezone>America/New_York</geoplugin_timezone>
	<geoplugin_currencyCode>USD</geoplugin_currencyCode>
	<geoplugin_currencySymbol>&#36;</geoplugin_currencySymbol>
	<geoplugin_currencySymbol_UTF8>$</geoplugin_currencySymbol_UTF8>
	<geoplugin_currencyConverter>0</geoplugin_currencyConverter>
</geoPlugin>



geoPlugin Currency Converter

Those of you paying attention to the output of geoPlugin's web services would have noticed that the output of the geoplugin_currencyConverter variable is a number.

This value represents the exchange rate of one US$ for your visitor. If you trade in US dollars, then this value is very convenient. You simply call the geoplugin_currencySymbol value (to display the visitor's local currency) then multiply the price of your product by the geoplugin_currencyConverter value.
Voila! The price of your product is now displayed to the visitor in his/her local currency, with the correct exchange rate for that day

However, what can you do if your base currency isn't the US$? For example, a French site wants to sell goods based on the €uro.
For this, you need to tell the geoPlugin web service (Javascript, PHP, JSON, and XML all work the same) that your base currency is not USD.
You do this by adding &base_currency=XXX after the IP address.eg

http://www.geoplugin.net/php.gp?ip=54.166.234.171&base_currency=EUR

Now geoplugin_currencyConverter will output the exchange rate of one Euro for your visitor.

The base_currency value must be the standard ISO 4217 3-letter code.



Adding Domains

(requires free registration)

Once you have registered and logged in, adding domains opens up the full potential of geoPlugin to those domains

Unless you specifically want geoPlugin on specific subdomains, register the main top-level domain, eg yourdomain.com that way all subdomains will be available to geoPlugin.
By doing this, you can always add specific subdomains later, if you require specific functionality (eg statistics) for specific subdomains.
In short, registering the main top-level domain is a catch-all for all domains under that main website.

Note: www.yourdomain.com is a subdomain. Even if your server is configured to treat www.yourdomain.com and yourdomain.com equally, geoPlugin does not know this. If you register www.yourdomain.com, then you will not be able to use yourdomain.com on geoPlugin, until you register it as a new domain. This is the most common mistake in getting your site to work with geoplugin!

To register a domain, login to the member area, and under Domain Management, click ”Add a domain”.
Once added, you will be sent an email on how to easily activate this domain.

Follow the instructions in the email you received when you registered a new domain to activate it.
No statistics nor geoPlugin javascript variables will be served until the domain is activated.

Note:If you do not activate a domain within 7 days of registering it with geoPlugin, it will be deleted from our records. If this happens, simply register the domain again, but this time activate it within 7 days!




See also

1) , 2) , 3) This product includes GeoLite data created by MaxMind, available from http://maxmind.com/
 
 


Acceptable Use Policy    Privacy Policy and User Agreement    Contact geoPlugin


©2006 - 2024 geoPlugin® is a registered trademark of GEOPLUGIN, SAS