Friday, October 7, 2011

Find Real IP address and location details of visitor

Find Real IP address and location details of visitor

Finding real IP address of a user is becoming highly important now-a-days, that too if the visitor is behind any firewall it's getting as a tough task for the webmasters to trace the real ip address of the visitor. Mostly all the webmasters make use of Google Analytics to trace their visitors, where in the IP address is masked. So, here i come with a solution with the help of the following

Language : PHP with CURL
Map API : Google Chart API


IPInfoDB offer a wide range of free services based on our IP address geolocation database :

  • Web based IP geolocation lookup

  • IP geolocation API (XML, JSON and CSV format)

  • IP database updated monthly!

To find the IP address of the user you will need to make use of the API in this tutorial, so register yourself for a FREEaccount.

Register at to get the API Key

About Google Chart

Google Chart Tools provide a perfect way to visualize data on your website. We will be using Visualization: Geochart.


* GetIpDetails
* Author : S.MohanKumar
* IP API from & Google Chart API
function GetIpDetails($realIp){
//check if you have curl loaded
if(!function_exists("curl_init")) die("cURL extension is not installed");
// create a new cURL resource
$ch = curl_init();
// API Key

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser

// close cURL resource, and free up system resources

return $ipDetails_json;
$obj = json_decode($ipDetails_json);

function getRealIpAddress()
if (!empty($_SERVER['HTTP_CLIENT_IP']))
//check ip from share internet
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
//to check ip is pass from proxy
return $ip;

getRealIpAddress(); // display the real IP address
echo "<br/>";
$ipDetails_json =GetIpDetails($openIp);
$obj = json_decode($ipDetails_json);
<script type='text/javascript' src=''></script>
<script type='text/javascript'>
google.load('visualization', '1', {'packages': ['geochart']});

function drawRegionsMap() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Country');
data.addColumn('string', 'Title');
data.setValue(0, 0, '<?php print $obj->{'countryName'}; ?>');
data.setValue(0, 1, 'IP : <?php print $obj->{'ipAddress'}." ".$obj->{'cityName'}.",".$obj->{'regionName'}.",".$obj->{'countryName'}; ?>');

var options = {};

var container = document.getElementById('map_canvas');
var geochart = new google.visualization.GeoChart(container);
geochart.draw(data, options);
<div id='map_canvas' style="width:600px"></div>

<legend><b>Ip Details </b></legend>
echo "<b>IPaddress :</b> ".$obj->{'ipAddress'}."<br/>"; // IpAddress
echo "<b>Country name :</b> ".$obj->{'countryName'}."<br/>"; // countryName
echo "<b>State name :</b> ".$obj->{'regionName'}."<br/>"; // regionName
echo "<b>City name :</b> ".$obj->{'cityName'}."<br/>"; // cityName
echo "<b>Latitude :</b> ".$obj->{'latitude'}."<br/>"; // latitude
echo "<b>Longitude :</b> ".$obj->{'longitude'}."<br/>"; // longitude
echo "<b>Time zone :</b> ".$obj->{'timeZone'}."<br/>"; // timeZone



  1. This comment has been removed by the author.

  2. Nice blog the script is helpful for those who dont knoe anything about how to find the ip address of visitors ..I used the script which you mentioned here and easily find the ip address of my website visitors .After finding the ip address i easily traced his location just by doing whois search for that ip address using sites like here they will display details like ip location ,ISP name ,address ,email id and so on but i can't trace exact home address of any person from ip ..I can trace only ISP details from ip address ..

  3. Mobile marketing is fastest growing tool of marketing that can give instant results on mass text messaging with active contact list. Get customers attraction need your catchy sms and good sms services like Top 5 Bulk SMS Service Provider in India with SMS API.

  4. However the want of such a device is justified on security grounds, several people do consider recording and tracing computers with IP addresses is a infraction of their secret. hide your IP address