-3

I need to make a custom code which will help me to find location of a particular IP entered through a text box. When I searched the internet what I found is only providing automatic detection of IP and it's location. Please help me.

thomas
  • 155
  • 1
  • 1
  • 6
  • 1
    You're searching bad. See this: http://stackoverflow.com/questions/7609083/php-ip-location?rq=1 – Alma Do Aug 14 '13 at 11:00
  • Why you people are not understanding my question. What I need is a location corresponding to an IP address inputted in an input box (text box) – thomas Aug 14 '13 at 12:21

2 Answers2

0

Take a look at the MaxMind GeoIP database. A tutorial for that one can be found at http://www.phpandstuff.com/articles/geoip-country-lookup-with-php. There are various other databases available as well. For that take a look at https://stackoverflow.com/search?q=geolocation+%5Bphp%5D

Community
  • 1
  • 1
ranieuwe
  • 2,268
  • 1
  • 24
  • 30
  • That is about getting location from an automatically detected IP. But what I need is to input an IP in a text box and to find the location for that particular IP. – thomas Aug 14 '13 at 11:08
0

I am using this code in my website

Please try it yourself -

<?php
function countryCityFromIP($ipAddr)
{
    $url = "http://api.ipinfodb.com/v3/ip-city/?key=5cfaab6c5af420b7b0f88d289571b990763e37b66761b2f053246f9db07ca913&ip=$ipAddr&format=json";
    $d = file_get_contents($url);
    return json_decode($d , true);
}

if(isset($_REQUEST['submit'])){
   $ip=countryCityFromIP($_REQUEST['ip']);

   //print_r($ip);
   echo $ip['cityName'];
}
?>


<form method="post">
<input type="text" name="ip" />
<input type="submit" name="submit" value="Find" />
</form>

please use print_r($ip); to get the details which parameter will get from the url.

Chinmay235
  • 3,236
  • 8
  • 62
  • 93