开发者

PHP Accessing the user's country (locale)

Is there a superglobal reference to the user's country or is using the IP against a database of IP to Country lookups the开发者_如何学Go best way to go?


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"]


Here are some more options for ip to country lookups

http://www.hostip.info/

http://pear.php.net/package/Net_Geo


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']}"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜