Ajax-php end received from the JavaScript Latin1 encoding length has become longer, to 16 to find more 0xc2,0xc3, etc.

Source: Internet
Author: User
Tags sha1

  
   ';    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);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.