问题原文
原帖链接 · user9371654 · CC BY-SA 4.0
Many websites directs the user to specific subdomains or domains based on their location. For example, if a user based in the UK types yahoo.com, the user somehow redirected to uk.yahoo.com. If the user is based on another country, say Japan, the user is redirected to jp.yahoo.com (this is just an example).
My question is: How web servers identify the users' locations? Is this only base don the IP? Are there any other techniques?
已采纳解答
原帖链接 · Michael d · CC BY-SA 4.0
From the research that I did on this years ago, I found that the only reliable method of country detection is through IP address. There are giant databases that list all of the IPs of various countries, though I found obtaining one of these databases to be very difficult at the time.
If you were able to get a database of all of the IP addresses in the UK, you could check for those IP addresses in PHP. This can be done with this PHP parameter:
$_SERVER['REMOTE_ADDR']
Update: Apparently MaxMind GeoIP has a database of country IPs that may work.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
