PHP 访问用户所在国家/地区(区域设置)

发布于 2024-08-11 01:20:35 字数 59 浏览 2 评论 0原文

是否存在对用户所在国家/地区的超级全局引用,或者使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼泪淡了忧伤 2024-08-18 01:20:35

我希望有这样的东西 $_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"]

太阳男子 2024-08-18 01:20:35

以下是 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

拥抱没勇气 2024-08-18 01:20:35

下面是如何从 IP 获取国家代码的示例。它不是 PHP 超全局变量,但也没有必要实现。

$country = strtoupper(file_get_contents("http://geoip.wtanaka.com/cc/{$_SERVER['REMOTE_ADDR']}"));

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.

$country = strtoupper(file_get_contents("http://geoip.wtanaka.com/cc/{$_SERVER['REMOTE_ADDR']}"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文