How to solve the garbled problem of php cookies

藏色散人
Release: 2023-03-08 18:52:01
Original
2237 people have browsed it

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.

How to solve the garbled problem of php cookies

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

Copy after login

Copy after login

js sets cookie PHP reads cookies

Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!