I’m decoding a string that was encoded in Python.
When using an online simulator for the decoding: https://www.base64decode.org/
The correct value is presented but when I’m decoding it on my end using PHP base64_decode
it returns garbage characters:
[“(“,”bean_id”,”=��M�MM̋LY �KM X�KNX��KY��X��L؍ ��H�
I’m guessing this has something to do with my charset?
The encoded string:
WyIoIiwiYmVhbl9pZCIsIj0+IiwiMDAxN2E1NzItMWQ2NS00NWJhLTljNzEtZGRmNmFiMzkzYjQ0IiwiKSJd
When decoded using the online simulator results in this:
[“(“,”bean_id”,”=>”,”0017a572-1d65-45ba-9c71-ddf6ab393b44″,”)”]
My code:
$page = $_GET['code']; $plainText = base64_decode($page); echo $plainText;
Additional information:
The problem occurs when I fetch the string from the url.
Advertisement
Answer
I was fetching the string in the URL using $_GET
Since it’s in the URL the +
will be transformed into a (Space)
That was causing the garbage character.
What I’m doing now to avoid this problem is to use urlencode
on my string after $_GET
so that the transformed characters will be returned to their original form.
Working late really has its downside. Thank you, everyone.