Home > Backend Development > PHP Problem > What should I do if php md5 and js are inconsistent?

What should I do if php md5 and js are inconsistent?

藏色散人
Release: 2023-03-14 21:32:02
Original
2808 people have browsed it

The inconsistency between php md5 and js is caused by encoding. The solution is to directly convert the Chinese in php and js into characters. The code is such as "md5(rawurlencode('Chinese content'));".

What should I do if php md5 and js are inconsistent?

The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer

What should I do if php md5 and js are inconsistent?

A simple solution to the inconsistency between Chinese php md5 and js md5

In the Chinese state, the md5 of php and the md5 of js are inconsistent, mainly due to encoding. We will not talk about conversion here. Encoded, troublesome, it can be solved by directly converting Chinese characters in php and js into characters:

md5 under php:

md5(rawurlencode('中文 内容'));
Copy after login

md5 under js:

md5.hex_md5(encodeURIComponent('中文 内容'));
Copy after login

Note: When php is transcoding, urlencode cannot be used. It will not transcode spaces, but js's encodeURIComponent will. This results in inconsistent results if the parameters contain spaces. Second, PHP's rawurlencode will transcode spaces just like js.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if php md5 and js are inconsistent?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template