PHP 访问用户所在国家/地区(区域设置)
是否存在对用户所在国家/地区的超级全局引用,或者使用 IP 来查找国家/地区 IP 数据库是最佳方法吗?
Is there a superglobal reference to the user's country or is using the IP against a database of IP to Country lookups the best way to go?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我希望有这样的东西
$_SERVER['HTTP_COUNTRY']
...也许在 php99 中? ;)目前, http://php.net/manual/en/book.geoip .php 是您最好的选择
,但是,如果您只对用户的语言感兴趣,则可以使用
$_SERVER["HTTP_ACCEPT_LANGUAGE"]
i wish there were such thing as
$_SERVER['HTTP_COUNTRY']
... maybe in php99 ? ;)for the time being, http://php.net/manual/en/book.geoip.php is your best bet
however, if you're only interested in user's language, there is
$_SERVER["HTTP_ACCEPT_LANGUAGE"]
以下是 IP 到国家/地区查找的更多选项
http://www.hostip.info/
http://pear.php.net/package/Net_Geo
Here are some more options for ip to country lookups
http://www.hostip.info/
http://pear.php.net/package/Net_Geo
下面是如何从 IP 获取国家代码的示例。它不是 PHP 超全局变量,但也没有必要实现。
Here an example of how to get country code from the IP. It's not a PHP superglobal, but it's not too had to implement either.