Solved

Get Client Browser preferences

Posted on 2003-10-29
7
225 Views
Last Modified: 2013-12-25
I am developing a web interface, which should work for multiple languages.
I am forcing the language to be displayed on the page with Header Environmenal Encoding META setting.
I would like to find a way to see if end user changes browser language from default so that I could adjust my script and during the next request, send the META option to set whatever user selected previously.

I can ask a user to select a language from the Drop-down box of course, but I would like to see a way to catch it when the browser's setting is changed (example: user selects "View" -> "Encoding" -> Unicode (UTF-8) on the browser menu).

Anybody knows a way to catch it?

Thank You.
0
Comment
Question by:sstouk
  • 3
  • 3
7 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 9654200
As you have posted this in "CGI Programming", are the pages generated by a CGI program?  If so, then don't rely on the META tag for setting the encoding as it will be overwritten by the http header.

There's no 100% reliable way to detect the current settings.  The closest you can get is using some Javascript.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9662953
if ($ENV{'HTTP_ACCEPT_LANGUAGE'} == 'en') { .. }
0
 
LVL 6

Author Comment

by:sstouk
ID: 9664278
thanks for your replies...
Tintin,
I am generating the Http header myself using cgi perl script.
And the question is about How to get the encoding setting.
Can you point me to some example that I could use if you know of any JavaScript that could help?

ahoffmann,

This just tells me the language, not the encoding.
I can perfectly get All the environmental settings using this method, but there's nothing there that would tell me the encoding.

the language is russian but it has at least 4 different encodings windows-1251, koi8-r etc...

I need this for the e-mail application that lists all the headers from incoming e-mail messages, recieved from different systems. They might send the message in different formats of the same language.

If I know what the current browser's encoding is, I can translate all the wrong encodings to the one, user would see properly.

Still,
How to get the encoding, set on the browser currently?

thanks again.
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 51

Accepted Solution

by:
ahoffmann earned 125 total points
ID: 9665450
hmm, koi8- etc.  think you're trapped
Which encoding is used by the browser is a browsr setting and will not be written in the request's header, usually, unfortunately.
You need to provide the correct encoding in your Web-Site.
Have a look at most common sites in .ru and you'll see that most offer an link to switch from one encoding to another.
A well programmed site even may offer this as CSS.

If you need to know the browser's prefered encoding, the link method is the most reliable, 'cause you then can use the URL and/or REFERER to check which encoding is currently used.
Hope this helps.
0
 
LVL 6

Author Comment

by:sstouk
ID: 9666776
This method - selectible form drop-down field I already implemented and it works, however I wanted to do it in the background, rather than complicate end-users with extra questions like "what is this encoding for...???"

If there is no other method, ahoffmann, you get the points. I just want this question to remain posted for some time to allow more experts to look at it.

Thanks.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9669311
beside HTTP_ACCEPT_LANGUAGE you can check HTTP_ACCEPT_CHARSET
it contains a semicolon-separated list of charsets.
If it contains koi8-r, koi8-u, windows-1251, iso-8859-5, ibm-855, iso-ir-111, cp-866 (probably some others) you got what you want.
0
 
LVL 6

Author Comment

by:sstouk
ID: 9744808
This is not a reliable way.
Some browsers do not support HTTP_ACCEPT_CHARSET variable...

Well, the solution here is posted by ahoffmann
Here's a solution:
"hmm, koi8- etc.  think you're trapped..."

And this is correct.
My research did not provide any answers and I am giving an end-user the drop-down list of selectable encodings which my script remembers and sets the web page to user's preference.

The script is  an e-mail client and e-mails are received from different servers, so it's up to the end-user to change the encoding and see a portion of e-mail subject lists in correct encoding, then to change the encoding and see the other half.

There is no other solution here, unless I provide the automatic recognition and encoding change of the incorrect e-mail messages... but this is too much work for now.... it's not commercial yet.

Thank You all for participating ...

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Ready Made PHP Scripts 5 79
Recursive folder search vbscript 7 55
Change the background and font colors in Notepad++ 5 107
Need script to search multiple files in one drive 13 55
This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question