473,416 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Russian characters in a cookie

Hi everybody,

could anybody help me with the following problem :

I need to set a cookie containing a Russian character string as the
value, using the construct "document.cookie = ...". The whole project
runs in the UTF-8 encoding.
The Internet Explorer handles this cookie correctly, whereas the
FireFox writes only some byte gargabe and then reads it back.

How can I solve it?

Regards

Victor

Oct 10 '06 #1
6 4337


Victor wrote:

could anybody help me with the following problem :

I need to set a cookie containing a Russian character string as the
value, using the construct "document.cookie = ...". The whole project
runs in the UTF-8 encoding.
The Internet Explorer handles this cookie correctly, whereas the
FireFox writes only some byte gargabe and then reads it back.
Nowadays (since JScript 4 and JavaScript 1.3) strings in JavaScript are
sequences of Unicode characters so a Russian (cyrillic?) character is
just another Unicode character in a JavaScript string. In terms of
string handling a Russian character should not pose any problems.

As for document.cookie, how exactly do you write a value in there, how
do you read it back? Where do you notice "byte garbage"? Do you use the
escape function to escape the cookie value before setting
document.cookie, do you use the unescape function on the cookie value
you get from document.cookie?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 10 '06 #2
First I have this function :

function setCookie (Bezeichner, Wert, Verfall) {
var jetzt = new Date();
var Auszeit = new Date(jetzt.getTime() + Verfall);
document.cookie = Bezeichner + "=" + Wert + "; expires=" +
Auszeit.toGMTString() + ";";
}

then I call it like this:

setCookie('Wert',someValue,123456789);

where someValue consists of Russian characters.

If I look into this cookie using FireFox Display Cookie Tool, there are
already only some badly identifiable characters inside. I could live
with it, as long as I would receive a proper content back, but this is
not the case here...

I evaluate this cookie in a PHP script on the server side thru
$HTTP_COOKIE_VARS, setting a variabe $wert, which gets printed in the
HTML-output. It read just the same what I had seen thru the FF Cookie
Tool before...

Strange enough, I have this problem only in the FF; the Internet
Explorer copes with it easily..

Victor

Martin Honnen wrote:
Victor wrote:

could anybody help me with the following problem :

I need to set a cookie containing a Russian character string as the
value, using the construct "document.cookie = ...". The whole project
runs in the UTF-8 encoding.
The Internet Explorer handles this cookie correctly, whereas the
FireFox writes only some byte gargabe and then reads it back.

Nowadays (since JScript 4 and JavaScript 1.3) strings in JavaScript are
sequences of Unicode characters so a Russian (cyrillic?) character is
just another Unicode character in a JavaScript string. In terms of
string handling a Russian character should not pose any problems.

As for document.cookie, how exactly do you write a value in there, how
do you read it back? Where do you notice "byte garbage"? Do you use the
escape function to escape the cookie value before setting
document.cookie, do you use the unescape function on the cookie value
you get from document.cookie?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 10 '06 #3


Victor wrote:
First I have this function :

function setCookie (Bezeichner, Wert, Verfall) {
var jetzt = new Date();
var Auszeit = new Date(jetzt.getTime() + Verfall);
document.cookie = Bezeichner + "=" + Wert + "; expires=" +
Auszeit.toGMTString() + ";";
Try whether
document.cookie = Bezeichner + "=" + encodeURIComponent(Wert) +
";expires=" + Auszeit.toGMTString() + ";";

improves things. If anything is UTF-8 encoded then PHP should deal with
that fine and url decode/unescape the value as needed when you access
$_COOKIE.

The cookie ends up as a HTTP header so without escaping stuff you should
run into problems.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 10 '06 #4
It seems that the encodeURIComponent() has improved the things, indeed.
Anyway, my cookie works now both in the IE and the FF.

Unfortunately, I did not understand how do you mean it with the
decode/unescape in the PHP...

Victor

Oct 10 '06 #5


Victor wrote:
It seems that the encodeURIComponent() has improved the things, indeed.
Unfortunately, I did not understand how do you mean it with the
decode/unescape in the PHP...
I was trying to suggest that PHP will correctly decode the cookie value
(that JavaScript encoded) automatically when you read out cookie values
from $_COOKIE (or $HTTP_COOKIE_VARS).


--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 10 '06 #6
Oh, yeah!

Thank you Martin!

Victor

Oct 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: M. Posseth | last post by:
hello ,, does someone know how i can acomplish the folowing task ,, i have a program with a HTML interface and i need to write Russian chars to the generated HTML files my database is...
5
by: Steven | last post by:
Hi all, I would like to create a site which shows text in English or in Russian (depending on the user's choice). Problem is that I can't save the pages in Unicode (Unicode can contain Russian...
1
by: Sonu | last post by:
Hello, I have a multilingual application, to which I am adding Russian. The prolem is that all the dialog boxes & Menus are showing junk characters instead of Cyrillics!! while my window contents...
2
by: Ross Noe via .NET 247 | last post by:
(Type your message here) -------------------------------- From: Ross Noe I created an XML file using ASP that has Russian characters. Forsome reason ASP.Net doesn't read the Russian...
3
by: Roger Withnell | last post by:
I am using ASP, VBScript and MSSQL Server. I do not understand the purpose of the VBS Codepage setting - <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> nor the meta tag - <meta...
1
by: Gerald | last post by:
Hi group, my question is both for asp.net. I have to do a website in Russian. So far, I have some problems with the russian character. Can someone give me good tips on how to make non ascii...
9
by: Roger Withnell | last post by:
I've built a site in English and an now translating it into Russian. My html charset= utf-8 and my vbscript codepage is 65001. I'm using DreamWeaver. If there is a Javascript function in a...
1
by: kersti | last post by:
We've just started to work on a Russian website. In the near future we expect to be running with a Japanese one as well. Currently our setup doesn't allow Russian characters - we need to do any...
1
by: sandeepindia | last post by:
I m using PHP Version 4.3.2 & Mysql version 3.23.58(No collation etc). My site is in shift JIS encoding. I've both japanese users & russian users. They have entered their member profile in their...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.