Home > Article > Backend Development > What should I do if php md5 and js are inconsistent?
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'));".
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('中文 内容'));
md5 under js:
md5.hex_md5(encodeURIComponent('中文 内容'));
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!