Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want my site to be able to locate a computers location, so if someone is accessing my site from london or manchester etc and to have users from a certain area displayed depending on their computers location. kind of like an online dating site that suggests users in your area.

I have been looking at this GEOIP database that lists all the cities around the world. But i dont know what to do next? Do i need to look at get ip address scripts that pull and compare the information from the GEOip database?

Please can someone point me in the right direction. Thanks.

GeoIP database from: http://dev.maxmind.com/geoip/geolite

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
447 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try the below code.

$ip =  $_SERVER['REMOTE_ADDR'];
echo $location = file_get_contents("http://api.hostip.info/country.php?ip=$ip");

Dont try this in your localhost. It will give the ip 127.0.0.1.

echo $location= file_get_contents("http://api.hostip.info/country.php?ip=12.215.42.19");
//outputs US

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...