HomeASP HostingWeb DesignRegister DomainSupportAbout Us

FAQ
Support :: FAQ


How to detect a visitorís language settings in ASP
You can detect the language settings of your visitorsí browsers in ASP and Iíll explain how to do that. The information about the language is in an HTTP header variable named HTTP_ACCEPT_LANGUAGE and you can access it from ASP through the Request.ServerVariables collection.

The following ASP code, will display the default language set in your browser, on your screen:

<%

Response.Write "The default browser language is set to: " & Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")

%>

Note that you may have more than one language set as default language in your browser. For example if you are in Canada and you use both English and French, your browserís language string might look like this: ďen-ca,fr-caĒ

Why would you want to know what are your visitorís language settings?

For example you might want to display your website in different languages, depending on the userís browser language settings. Consider the example below, which will display one and the same greeting in 3 different languages, depending on the userís language settings:

<%

sLanguage = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")

If InStr(sLanguage, "fr") <> 0 Then
  Response.Write "Bonjour"
ElseIf InStr(sLanguage, "es") <> 0 Then
  Response.Write "Hola"
Else
  Response.Write "Hello"
End If


%>
© Copyright 2001-2004 Art Branch Inc.