Client Cookie (below)

Source: Internet
Author: User

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.

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.