Cookie| Programming | client | Chinese For example, the cookie content you want to write is "an ABC", changed to "99A98A97A-31029A26432A" (based on security considerations, reverses the string), and then after the escape code becomes " 99A98A97A%2D31029A26432A "(Escape encoding converts characters other than letters and numbers to hexadecimal%xx), and note that delimiters do not select%,d and numbers. Of course, if you have important information like a password, you need to reinforce it on the encryption. Since writing cookies is generally a short message, some of the bytes added after encoding are negligible. The following JavaScript read-write cookie function adds 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 you write a Chinese cookie in a CGI program, the client reads it. In the case of ASP, you can use the previously described encoding function, and then write with response, for example: Response.Cookies ("Name") =codecookie ("John") to this point, the problem of Chinese cookies is basically resolved.