Errors related to garbled characters during cookie passing in PHP

Source: Internet
Author: User
Garbled error in cookie passing value in PHP $ usernamemb_convert_encoding ($ row1 [0], & quot; GBK & quot;, & quot; UTF-8 & quot;); setcookie (username, $ username); this setcookie will cause garbled characters on the page, but an error will be reported through setrawcookie. for the error of undefined functions, ask the PHP question about garbled characters when passing the cookie value.
$ Username = mb_convert_encoding ($ row1 [0], "GBK", "UTF-8 ");
Setcookie ('username', $ username );
Garbled characters will appear on the page through setcookie
However, an error is reported through setrawcookie, indicating that the function is not defined.
How to write and read cookies

------ Solution --------------------
Is the cookie you set for js?
If yes, garbled characters are caused by a problem with the function for reading cookies.
If it is a php application, you can convert the UTF-8 encoded content to gbk. Isn't it gbk? If it is not transferred back, it will be garbled.
------ Solution --------------------
Upstairs, $ username = mb_convert_encoding ($ row1 [0], "GBK", "UTF-8 ");
Setcookie ('username', $ username );
You can try setrawcookie. In fact, transcoding is enough for output.
$ A = mb_convert_encoding ($ _ COOKIE ["username"], "UTF-8", "GBK"); it's OK. try it.

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.