Solved

Get Client Browser preferences

Posted on 2003-10-29
7
220 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now