|
List of free |
| Response to visitor depending on the languages selected in the browser |
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:
Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
In the table bellow we have use an script to identify the languages
selected in your browser. You may get the complete code here.
The list of languages may be obtained here.
|
The languages selected in your browser: English/United Satates English |
In the table bellow are displayed the different values for Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
obtained
from visitors to my home page.
| Values for Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
obtained from 164 visitors to asptutorial.info main page: 84 en-us
|
Redirecting visitors to lenguage specific pages
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 Request.ServerVariables("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:
| defauldpage.asp |
| <% if Instr(1,Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"), "es",1)>0
then
response.redirect("spanishpage.asp") end if %> <html>
Page into English, my defauld language </body>
|
In line 1 we will check whether substring "es" is included in value for Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"). Our comparation will start in character number 1 of the string, and it will not be case sensitive (see Compare strings page for explanation).
If comparation is true the user will be redirected to the page in Spanish
(line 2). When redirection is performed, the rest of information in the
page is not transferred to the clients browser. If the comparation is false,
the remaining information in the page is send to the client.
Option 2 (Spanish is in the list, but the user only knows
Spanish when this language is the first one in the list. If it is so, we
will redirect the user to the page in Spanish)
| defauldpage.asp |
| <% if Mid(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"), 1,2)="es"
then
response.redirect("spanishpage.asp") end if %> <html>
Page into English, my defauld language </body>
|
In line 1 we will get the two first positions for Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") and we will check whether its value is "es" (see Manipulate Strings page for explanation).
If comparation is true the user will be redirected to the page in Spanish
(line 2). When redirection is performed, the rest of information in the
page is not transferred to the clients browser. If the comparation is false,
the remaining information in the page is send to the client.
Showing lenguage specific ads or text
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 list of
lenguages selected in the browser, the user knows Spanish, so we will display
an ad or text in Spanish. In the script bellow we will show ads:
| languagespecificad.asp |
| <html>
<title>My page</title> <body> <% if Instr(1,Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"), "es",1)>0 then %> <a href=http://www.link1.com><img scr=spanishad.gif></a> <% else %> <a href=http://www.link2.com><img scr=englishad.gif></a> <% end if %>
My info </body>
|
Code for ad in Spanish will be the red one (if comparation is true)
and code for ad in English will be in magenta (if comparation is false).
In order to display text instead of ads or figures, we just need to
substitute the corresponding code.
|
|
Create word search puzzles with your own words
|
2008@ AspTutorial.info. All rights reserved.