大网数据广告活动
网站运营与故障问答

How do web servers identify the client's location

· 52CE 我爱测

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 countr…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。