How to get the geolocation details of the user during a website visit

Hi, You will learn in this tutorial how to get the geolocation details of the user during a website visit. Basically, we need the visitor's location details to analyze the site webmasters to know which country users are visiting the site and also some area wise reports and interested post published on the website, For which post gains more traffic from the particular country or region. And also this is very useful when a website is a done in the country wise website like

http://in.example.com/
http://us.example.com/
http://fr.example.com/
http://de.example.com/

In this situation also we need to collect the visited user's geolocation. Because we collect the user's geolocation then we will redirect the user to based on the country website.

Suppose if a user is visited the http://www.example.com/ the user is coming from the united states then we will redirect to the http://us.example.com/

To do this by using a simple plugin i.e geo plugin. By using this plugin we can get the visited user's information like city, region, Country Name, Country Code, Currency Code, etc..

You need to download the geoplugin library and call it on your page.
http://www.geoplugin.com/_media/webservices/geoplugin.class.phps
 <?php  
 require_once('geoplugin.class.php');  
 $geoplugin = new geoPlugin();  
 //locate the IP  
 $geoplugin->locate();  
 echo "Geolocation results for {$geoplugin->ip}: <br />\n".  
      "City: {$geoplugin->city} <br />\n".  
      "Region: {$geoplugin->region} <br />\n".  
      "Area Code: {$geoplugin->areaCode} <br />\n".  
      "DMA Code: {$geoplugin->dmaCode} <br />\n".  
      "Country Name: {$geoplugin->countryName} <br />\n".  
      "Country Code: {$geoplugin->countryCode} <br />\n".  
      "Longitude: {$geoplugin->longitude} <br />\n".  
      "Latitude: {$geoplugin->latitude} <br />\n".  
      "Currency Code: {$geoplugin->currencyCode} <br />\n".  
      "Currency Symbol: {$geoplugin->currencySymbol} <br />\n".  
      "Exchange Rate: {$geoplugin->currencyConverter} <br />\n";  
 ?>  
Here you can download the Full Source code and check the demo.

Download Demo
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff


EmoticonEmoticon