proctk Posted April 15, 2007 Share Posted April 15, 2007 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 More sharing options...
suttercain Posted April 15, 2007 Share Posted April 15, 2007 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. Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229788 Share on other sites More sharing options...
proctk Posted April 15, 2007 Author Share Posted April 15, 2007 I'm thinking that the company that owns or registered your ip address in in the place that it show. I still want to know how they get that information. Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229793 Share on other sites More sharing options...
neel_basu Posted April 15, 2007 Share Posted April 15, 2007 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 to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229794 Share on other sites More sharing options...
clown[NOR] Posted April 15, 2007 Share Posted April 15, 2007 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... Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229808 Share on other sites More sharing options...
suttercain Posted April 15, 2007 Share Posted April 15, 2007 Yeah, what they do, is if it is wrong they ask you to submit the correct city and country. They then save that data to their database and use a comparison in the future for someone who may come with a similar IP. Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229814 Share on other sites More sharing options...
neel_basu Posted April 15, 2007 Share Posted April 15, 2007 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. Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229819 Share on other sites More sharing options...
proctk Posted April 15, 2007 Author Share Posted April 15, 2007 I'v played around with geoip i get the coordinates but don't know how to change them into someones location Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229854 Share on other sites More sharing options...
proctk Posted April 15, 2007 Author Share Posted April 15, 2007 here is a link to the tutorial http://bakery.cakephp.org/articles/view/332 Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229864 Share on other sites More sharing options...
ted_chou12 Posted April 15, 2007 Share Posted April 15, 2007 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 />"; ?> Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229880 Share on other sites More sharing options...
suttercain Posted April 15, 2007 Share Posted April 15, 2007 I tried it, and it again gives me Country: UNITED STATES (US) City: Reston, VA Google Map: Link Which I guess is where they think I am.... But the code seems to work for the most part. Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229898 Share on other sites More sharing options...
ted_chou12 Posted April 15, 2007 Share Posted April 15, 2007 thanks, i see. Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229903 Share on other sites More sharing options...
proctk Posted April 15, 2007 Author Share Posted April 15, 2007 Thank you for the help that worked excellent, for the people that get a different city I'm thinking its because the persons ISP head office is in that city and that is here that ip addess is assigned. this is just an educated guess Link to comment https://forums.phpfreaks.com/topic/47124-get-ip-address-location-city/#findComment-229904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.