1

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?

3 Answers 3

2

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

1
  • Funnily enough, some providers include the MaxMind GeoIP module in PHP which provides country information in the $_SERVER variable: maxmind.com/app/php - very, very rare, though.
    – Pekka
    Nov 15, 2009 at 0:14
0

Here are some more options for ip to country lookups

http://www.hostip.info/

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.