Good day all,
I ran this code online
echo urldecode(base64_decode(‘cGFwYWRhbW15QHlhaG9vLmNvbQ%3D%3D’));
and it gave me this
papadammy@yahoo.com
��
The last two characters are not supposed to be part of the answer, what am I doing wrong?
Thanks in advance for your reply.
Thanks spaceshiptrooper, it worked. The challenge now is that if I encode papadammy@yahoo.com , it will produce “cGFwYWRhbW15QHlhaG9vLmNvbQ%3D%3D”. I need this encoded thing to work without any manual interference for password recovery system. Any other idea?
I’ve tested a couple of emails and I discovered this problem is common with yahoo mail. I think the solution will be to find a way of removing %3D from any decoded variable having such.
Why not try this:
$str = str_replace('%3D', '', 'papadammy@yahoo.com');
echo urlencode(base64_encode($str));
Marc_Towler:
str_replace
Not tested, but does str_replace work with padding"
In computer programming, Base64 is a group of binary-to-text encoding schemes that represent binary data (more specifically, a sequence of 8-bit bytes) in sequences of 24 bits that can be represented by four 6-bit Base64 digits.
Common to all binary-to-text encoding schemes, Base64 is designed to carry data stored in binary formats across channels that only reliably support text content. Base64 is particularly prevalent on the World Wide Web where one of its uses is the ability to embed image fi...
I just tested the code and it works…
encoded: cGFwYWRhbW15QHlhaG9vLmNvbQ%3D%3D
decoded: papadammy@yahoo.com
I made a slight issue with what I put above so the actual code would be:
<?php
$str = 'papadammy@yahoo.com';
$enc = urlencode(base64_encode($str));
echo "encoded: " . $enc;
$enc = str_replace('%3D', '',$enc);
$dec = urldecode(base64_decode($enc));
echo"<br />decoded: " . $dec;
The above will output the encoded string and then the decoded string working fine, just go from there to get the exact result you want
2 Likes
papadammy:
what am I doing wrong?
If you base64_encode first and then urlencode second (which is the order they have to be in to get that string to be decoded in the first place) then to decode the string you need to urldecode first and base64_decode second
echo base64_decode(urldecode('cGFwYWRhbW15QHlhaG9vLmNvbQ%3D%3D'));
Then the encoded %#D %3D will be converted back to == first and then discarded automatically.
The way round that you have it you are trying to base64 decode a string that isn’t all base64
1 Like
To everyone of you who took time to educate me on this, I am really grateful. Thank you all.
system
Closed
March 6, 2016, 5:56am
10
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.