Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting language from PHP

Status
Not open for further replies.

rastkocvetkovic

Programmer
Aug 11, 2002
63
SI
As you probably noticed, especially people living outside US or UK, noticed that google.com started working in your native language - German, French, Italian, even Slovenian... Now I'm wondering, how is it possible for them to know what kind of language settings am I using on my PC? Is that possible to find out using PHP?

Thank you for your answers, regards

Rastko
 
Yes, that information is available to PHP.

Your browser sends language settings to the server in an HTTP header called "Accept-Language:". PHP makes that information available in the variable $_SERVER['HTTP_ACCEPT_LANGUAGE'].

If multiple languages are listed in the list, the first is assumed to be the user's preferred language. ______________________________________________________________________
TANSTAAFL!
 
i don't think that this is how google does it.

we have a satallite internet connection that is provided to us by a german company (we are based in the UK) when we load up google.com we get the german version of the site i think google looks at the ip address, and somehow allocates you to a country. not knowing too much about IP addresses structure but this is what i think that they do
 
arperry,

I have English-US, German, and Russian languages all configured in my browser language lists. When I move German to the top of the list of languages and refresh, Google brightly offers me a link to "Suchtipps" to me. When I move Russan to the top of the list, I see Cyrillic. When I move English-US to the top of the list, Google is in English. This works in both Opera and IE.

It's got to be the browser "Accept-Language" string that Google's reading. You might want to check which language is at the top of the list in your browser settings. The language at the top is the default language for content. ______________________________________________________________________
TANSTAAFL!
 
I disagree with you, arperry is correct as I have a collegue who has the same system running through Germany.

I know there is a setting structure in Apache to server different pages based on Language (country of origin of request), but you are going to have to look that up yourself.
 
LittleHavoc:

Apache (and other web browsers) only react to the HTTP headers they receive. According to RFC 2068, "The Accept-Language request-header field is similar to Accept, but restricts the set of natural languages that are preferred as a response to the request."

It is still possible that your colleague using the ISP has German as his first language preference, or he is sitting behind an HTTP proxying server.

Try my experiment and see if you don't duplicate my results.
______________________________________________________________________
TANSTAAFL!
 
There is another possibility.

If you point your web browser to you're going to get German regardless of your language settings.

The same, in English, for
It is that reacts to language settings. I infer that the non-US sites are assumed to be single-language. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top