'; echo $username_php; echo '
'; echo strlen($username_php); echo '
'; echo bin2hex($username_php); echo '
';?>
The code JS end of the self-output
sha1_latin:>6gjº>%qxpâlðø//This segment is a string generated by SHA1 ("ABC")
Latin.len:20
hex:a9993e364706816aba3e25717850c26c9cd0d89d//This section is a 16 binary string form of Sha1_latin, you can determine that the hex conversion is correct here
And after being transferred to PHP via Ajax, the output in the browser-side
>6gjº>%qxpâlðø//here is still in front of the Sha1_latin correspondence
29//the length here is wrong.
c2a9c2993e364706c2816ac2ba3e25717850c3826cc29cc390c398c29d//conversion to 16 binary discovery and the previous hex is not the same, the observation found a few more c2,c3, ask is why?????
Reply content:
'; echo $username_php; echo '
'; echo strlen($username_php); echo '
'; echo bin2hex($username_php); echo '
';?>
The code JS end of the self-output
sha1_latin:>6gjº>%qxpâlðø//This segment is a string generated by SHA1 ("ABC")
Latin.len:20
hex:a9993e364706816aba3e25717850c26c9cd0d89d//This section is a 16 binary string form of Sha1_latin, you can determine that the hex conversion is correct here
And after being transferred to PHP via Ajax, the output in the browser-side
>6gjº>%qxpâlðø//here is still in front of the Sha1_latin correspondence
29//the length here is wrong.
c2a9c2993e364706c2816ac2ba3e25717850c3826cc29cc390c398c29d//conversion to 16 binary discovery and the previous hex is not the same, the observation found a few more c2,c3, ask is why?????
Because the string is transcoded into another encoding. Did you find that the characters that were added above are those that are c2
c3
greater than or equal 0x80
?
Workaround, set page encoding, transfer encoding, PHP receive encoding consistent, all to Latin1
prevent browser or PHP automatic transcoding
Why not pass a9993e364706816aba3e25717850c26c9cd0d89d
the string?
xmlhttp1.open("GET","web/tes.php?sha1_html="+sha1_hex,false);//发送G给服务器xmlhttp1.send();document.write(xmlhttp1.responseText);