Language specific response
Knowing the languages selected in the browser of our visitors may be a very important data we may used to redirect the user to a specific page in the corresponding language, or to display specific information directed to the user (as for example the most suitable ad).
The basic command we will use to know the languages selected in the browser is this one:
In the table bellow are displayed some values for $_SERVER["HTTP_ACCEPT_LANGUAGE"] obtained
from visitors to my home page.
Let suppose we have our information in English and Spanish, and we will also suppose spanish is not the more used language by our visitors (our default language will be English)
By using $_SERVER["HTTP_ACCEPT_LANGUAGE"] we may know whether Spanish is one of the languages selected in the browser of our visitor. If it is so, we may consider to situations:
In line 2 we will check whether substring "es" is included in the variable $_SERVER["HTTP_ACCEPT_LANGUAGE"].
If comparation is true, a Spanish file is included
Option 2 (Spanish is in the list, but the user
Spanish when this language is the first one in the list. If it is so,
will show the page in Spanish)
In line 2 we will get the two first positions from
$_SERVER["HTTP_ACCEPT_LANGUAGE"] by using function substr,
and we will check whether its value is "es".
This example will work basically in the same way shown for previous example.
In this case we will assume that if Spanish is in the
lenguages selected in the browser, the user knows Spanish, so we will
an ad or text in Spanish. In the script bellow we will show ads:
Spanish ad is the red code (if comparation is true)
and English one is in magenta (if comparation is