GEOIP and getting a computers IP address Location?

2019-01-24 14:38发布

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

标签: php ip
7条回答
2楼-- · 2019-01-24 15:42

PHP has builtin functions for GeoIP

GeoIP library

This one function may be particularly useful as it will return continent, country, city etc. in an array.

geoip_record_by_name

Use $_SERVER['REMOTE_ADDR'] as your ip.

$record = geoip_record_by_name( $_SERVER['REMOTE_ADDR']);

查看更多
登录 后发表回答