Client Cookie Chinese programming _ MySQL

Source: Internet
Author: User
In the use of cookies, we found a problem: if the content written into the Cookie is in Chinese (such as the user name), the server-side program (such as ASP or PHP) should read it completely correctly, however, a bunch of garbled characters are extracted using the common JavaScript or VBScript's read Cookie function. This is a tricky problem, because in some cases, the Cookie content needs



In the use of cookies, we found a problem: if the content of the Cookie written is in Chinese (such as the user name), use the server program (such as ASP
Or PHP), but a bunch of garbled characters are obtained using the general JavaScript or VBScript read Cookie function. This is a tough issue,
In some cases, the Cookie content needs to be read in the script language on the client side. If you write Chinese characters and get a bunch of garbled characters, doesn't it feel so bad?
Awkward? To solve this problem, we should also start with the Cookie access method.
We know that escape (hexadecimal encoding) is required before the Cookie content is written, and the encoding is in bytes. this is the key to the problem.
In: any Chinese character is split into two bytes for encoding, while in the Cookie reading, unescape decodes the characters in bytes. Therefore, each Chinese character is changed.

Into two byte garbled characters. What should we do? The ASP or PHP method can be correctly read. it should be after the unescape decoding, and then according to the unicode encoding
Words are spelled out. If so, can we find a work und to solve this problem? After careful research, we found that as long as the hexadecimal codec
It is enough to store Chinese characters in the process. Therefore, we need to outsource a codec process. The solution is as follows:

1. before escape encoding, convert each character in the Cookie string to a unicode character string format (separated by a special character as a string ).
).

2. after decoding unescape, extract all unicode strings and convert them to the original character using the corresponding function.

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.