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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With