php The solution to garbled cookies: First, when writing the Cookie, encode it with Url; then rewrite the Cookie; and finally decode the Url when reading.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
php and js when transferring cookies to each other in Chinese The problem of garbled characters
js stores cookies, and when PHP reads them, they become garbled characters.
Problem Analysis:
This is caused by character encoding. Chinese characters have two encodings, so such garbled codes are produced!
Solution:
1: When writing Cookie, first encode it with Url, and then write it
2: When we read it, decode the Url. Can
php two functions
urlencode()
urldecode()
js two Function
decodeURI()
encodeURI()
php sets cookie, js reads cookie
js sets cookie PHP reads cookies
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to solve the garbled problem of php cookies. For more information, please follow other related articles on the PHP Chinese website!