Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP base64 decode returns garbage characters

Tags:

php

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.

like image 368
magicianiam Avatar asked Oct 21 '25 04:10

magicianiam


1 Answers

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.

like image 139
magicianiam Avatar answered Oct 22 '25 18:10

magicianiam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!