Client Cookie Chinese programming (next)

Source: Internet
Author: User
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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.