1

Possible Duplicate:
Simplest way to detect client locale in PHP

I am using PHP in my code. I wanted to know if there was any way to display content according to a specific country.

For example - the webpage shows the average height of the people of a country.

So I want that if anyone from the US connects to the website, they get the result as:

The average height of the people of US is 6,5 feet.

Suppose a person from China connects, then he should get:

The average height of the people of China is 5,4 feet.

Community
  • 1
  • 1
Yahoo
  • 4,093
  • 17
  • 59
  • 85
  • Please have a look at: http://stackoverflow.com/questions/297542/simplest-way-to-detect-client-locale-in-php – Jelmer Sep 17 '12 at 07:32

1 Answers1

0

You could either look at HTML5 geolocation api, take the cords you get from those calls and look what country they belong to with for example the geonames api. There are other location api's out there as well that might suit better, though.

A much shorter but less precise solution is to look at the browser accept-language info. It has an array with language-codes with the preferred languages for this browser, sorted from the left. As far as I know, Accept-Language is affected by OS-language as well if browser settings are not tampered with.

Exact syntax to get the info differs from language to language, for PHP it's:

$_SERVER['HTTP_ACCEPT_LANGUAGE'];

Then it's up to you to parse the string/array and display the correct page using that info.

Daniel Hallqvist
  • 822
  • 5
  • 15