For example, if the Cookie content you want to write is "abc", after CodeCookie is changed to "99a98a97a-31029a000032a" (reverse the string based on security considerations ), after escape encoding, it becomes "99a98a97a % 2d31029a000032a" (escape encoding converts characters other than letters and numbers to hexadecimal % XX format). Note that the separator cannot be set to %, D and number. Of course, if you have important information similar to a password, you need to encrypt it. Because Cookie writing is generally short messages, some bytes added after encoding are negligible. The following JavaScript Cookie reading and writing functions include the above Chinese support.
Function SetCookie (name, value, expires)
{
Var exp = new Date ();
Exp. setTime (exp. getTime () + expires * 60*1000 );
Document. cookie = name + "=" + escape (CodeCookie (value) + "; expires =" + exp. toGMTString () + "; path = /";
}
Function GetCookie (name)
{
Var strArg = name + "= ";
Var nArgLen = strArg. length;
Var nCookieLen = document. cookie. length;
Var nEnd;
Var I = 0;
Var j;
While (I $ # @ 60; nCookieLen)
{
J = I + nArgLen;
If (document. cookie. substring (I, j) = strArg)
{
NEnd = document. cookie. indexOf (";", j );
If (nEnd =-1) nEnd = document. cookie. length;
Return DecodeCookie (unescape (document. cookie. substring (j, nEnd )));
}
I = document. cookie. indexOf ("", I) + 1;
If (I = 0) break;
}
Return null;
}
If the CGI program is used to write a Chinese Cookie, the client reads the Cookie. For example, in ASP, you can use the preceding encoding function and then write it with response, for example: response. cookie ("Name") = CodeCookie ("Michael") now, the problem of Chinese cookies is basically solved.