Response to visitor depending on the lang 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

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 codedcode.com main page:

84 en-us 
9 en-gb
9 de
7 nl
5 en-us,zh;q=0.5
4 es
4 en
3 nl-be
3 it
3 eu,en,es
3 en-za
3 en-us,el;q=0.5
3 en-ie
2 pt-br
2 fr-ca
2 es-mx
2 en-us,hi;q=0.5
1 zu;q=0.3
1 th
1 sv
1 sl
1 ro
1 pl
1 in
1 he
1 fr-ch
1 fr
1 en-ca
1 en-au
1 en;q=0.7,
1 en,fr-CA
1 de-ch
1 bg

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:

  • Spanish is the first language (p.e: Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") value is "es,en")
  • Spanish is not the first langauge (p.e: Request.ServerVariables("HTTP_ACCEPT_LANGUAGE") value is "en,es")
We may consider also two other situations:
  • If Spanish is in the list, the user knows Spanish
  • The user knows Spanish only when Spanish is  the first langauge in the list
Option 1 (If Spanish is in the list, the user knows Spanish, so we will redirect the user to the page in Spanish)
 
defauldpage.asp
<% if Instr(1,Request.ServerVariables("HTTP_ACCEPT_LANGUAGE"), "es",1)>0 then
response.redirect("spanishpage.asp")
end if %>

<html> 
<title>Page into English, my defauld language</title> 
<body> 

 Page into English, my defauld language

 </body> 
 </html>

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> 
<title>Page into English, my defauld language</title> 
<body> 

 Page into English, my defauld language

 </body> 
 </html>

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> 
 </html>

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.



Google






   



MSN Nick Name



More Resources...





Most Viewed Services:
  1. HTML Tutorial
  2. XHTML Tutorial
  3. CSS Tutorial
  4. Javascript Tutorial
  5. DHTML Tutorial
  6. VB Script
  7. TCP/IP Tutorial
  8. ADO Tutorial
  9. MYSQL Tutorial
  10. ASP Tutorial
  11. AJAX Tutorial
  12. CFML Tutorial
  13. PHP Tutorial
  14. WML Tutorial
  15. FLASH Tutorial
  16. XML Tutorial
  17. RSS Tutorial
  18. SQL Tutorial
  19. HTML Articles
  1. Javascript Articles
  2. PHP Articles
  3. SEO Articles
  4. Web Design Articles
  5. SEO Tips
  6. Web Design Tips
  7. Articles
  8. CSS
  9. CSS Tips
  10. HTML Tips
  11. JAVASCRIPT Tips
  12. MYSQL Tips
  13. PHP Tips
  14. Money
  15. Tutorials
  16. Web Hosting



  • Home
  • Web Directory
  • Top Directoriers
  • Webmaster Directories
  • Contact
  • © Copyright 2006-2010 All Rights Reserved By CodeDcode.Com : HTML : RSS : TEXT : XML