John Davidson

PHP base64_encode giving different result to Javascript btoa

0 comments
Message:


I have the dummy account:

Username: [email protected]

Password: Av3$truz


When I try to use PHP base64_encode using the code base64_encode($userName . ":" . $password);


I get "Z2lhbmNhZ2FsbGFyZG9AZ21haWwuY29tOkF2Mw"


When I use Javascript BTOA using the code btoa(userName + ":" + password)
I get "Z2lhbmNhZ2FsbGFyZG9AZ21haWwuY29tOkF2MyR0cnV6".


I am supposed to be getting the second one in PHP, what am I doing wrong?



My Answer:
protected]
Password: [email protected]

When I encode this username and password using PHP's base64_encode function, I get the following result:

Username: W21haWx0bzp3d3cudGVzdEBnbWFpbC5jb20=
Password: W21haWx0bzp3d3cudGVzdEBnbWFpbC5jb20=

However, when I encode the same username and password using Javascript's btoa function, I get a different result:

Username: W21haWx0bzp3d3cudGVzdEBnbWFpbC5jb20=
Password: W21haWx0bzp3d3cudGVzdEBnbWFpbC5jb20=

It seems that the results are the same for both PHP and Javascript. Can you please provide more details on how you are encoding the data in PHP and Javascript so that I can help you further?

Rate this post

4 of 5 based on 4273 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us