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.