Jump to content

get ip address Location City


proctk

Recommended Posts

Hi

 

I have been to website that show my Ip address, flag and city location.  How do I do this so that I can get the vistors city and assign it to a variable so that I can use it in a mysql query.

 

I found this website but can not figure out how they are doing it.

 

http://www.hostip.info/use.html

 

any help is excellent

Link to comment
https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/
Share on other sites

When I read your question I didn't think they could look-up my location, but after visiting that site, I know they can't.

 

When I visited it said:

 

"Reston, VA, UNITED STATES

IP found in 0.0079 seconds"

 

I am in San Dimas, CA (Los Angeles) not Reston, VA.

 

UPDATE:

Upon further investigation I see what they are doing. They are building their own database, where the users enter the information for their IP address. Based on that they run a script which tries to guess your location based on previous entires. This is obviously an inaccurate way of determining an IP address, since they got mine wrong.

 

I would guess the more user submitted info they get the more accurate it will become in the future.

 

But there is now way to just get an IP and say you're here.

I think they either they have edited geoIP dat File by themselves and then using that.

or Maxmind IP Database (they have edited that)

It didn't Show my location correctly

I am From India -> Calcutta they Shown India -> Tiruchirapally

mile away from my location

link=topic=136132.msg574944#msg574944 date=1176659990]

they got the ip and country right on me... but the city...hehe...ehm... it's on the other side of norway from where I live...

Its Simple probability of getting errors in country in very very low. where as its high in case of city.

GeoIp is the best Solution.

please try this script and tell me if it works or not:

<?php 
$ip = $_GET['ip'];
$content = file("http://api.hostip.info/get_html.php?ip=$ip&position=true");
$country = str_replace("Country: ", "", $content[0]);
$city = str_replace("City: ", "", $content[1]);
$lat = str_replace("Latitude: ", "", $content[2]);
$long = str_replace("Longitude: ", "", $content[3]);
echo "Country: $country<br />";
echo "City: $city<br />";
echo "Google Map: <a href=\"http://maps.google.com/maps?ll=$lat,$long\">Link</a><br />";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.