PHP - 如何检测用户位置[重复]

This question already has an answer here:

I am developing web application and i need to know the location of the user they connecting from

For example this website www.craigslist.org it can detect my location and redirect me to sub domain So, it's redirect to:

cairo.craigslist.org

boston.craigslist.org/

What is the best way to do that with PHP ?

PART TWO

How can i make it redirect to subdomain with country/city ? like the above example ?

</div>

In pure PHP without a 3rd party service, take a look at the GeoIP extension library: http://php.net/manual/en/book.geoip.php

You'll be highly limited using this however to country, region, and ISP. I think the State and City longitude and latitude starts getting less accurate.

You could also check out https://github.com/maxmind/GeoIP2-php which seems to be a library intended to replace GeoIP.