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.
Asked
Active
Viewed 1,826 times
-3
-
1You'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 Answers
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
-
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
-
This code is not working. Can you combine the whole code as one and paste it here. – thomas Aug 14 '13 at 12:00
-
-
-
Is there any other code which can provide details like, country, area code, currency, longitude, latitude, time zones etc. – thomas Aug 14 '13 at 13:16
-
-
Hello please download file http://www.ip2location.com/downloads/ip2location-php-6.0.0.zip and read the developer document http://www.ip2location.com/developers/php – Chinmay235 Aug 14 '13 at 13:28
-
Chinmay Sahu, can you help me with showing google maps from the ip entered in the above code. – thomas Aug 16 '13 at 16:18
-
In above code returns the address then put this address in your dynamic location map parameter url. Thanks. – Chinmay235 Aug 17 '13 at 09:27
-
can you paste a code for that, I am not that good with coding. Chinmay Sahu – thomas Aug 18 '13 at 11:24
-