|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36946 base64_decode doesn't work
Submitted: 2006-04-02 10:49 UTC Modified: 2006-04-02 14:13 UTC
From: kirlo at gmx dot de Assigned:
Status: Not a bug Package: *URL Functions
PHP Version: 5.1.2 OS: windows & debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
9 + 42 = ?
Subscribe to this entry?

 [2006-04-02 10:49 UTC] kirlo at gmx dot de
we're encoding some text data with base64 with a small application (not php) on a client pc, then we'll send it to a webserver via POST or GET. the PHP script is fetching POST or GET without any problems but it does not correctly perform the base64_decode operation. we checked our base64 encoded text with other tools (for example ) and they had no problems!
this system works with the latest php4 version but it does not work with the latest php5 version (on the earlier version it also worked well!). i already tried the latest CVS snapshot but it didn't worked either.

Reproduce code:
very simple:

echo base64_decode($_POST[base64text]);

Expected result:
here are three files
the original text:
the base64 encoded text (base64 encoding performed by our client application):

the base64_decode output:

in this case the messed up text is at the end of the text. sometimes the messed up text is starting at the first 2 or 3 lines.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-02 11:51 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

 [2006-04-02 12:10 UTC] kirlo at gmx dot de
well that's mysterious - this script will work without any problems (put my base64encoded.txt into the scriptdir):
$fp = fopen ("base64encoded.txt", "r");
$str = fread ($fp, filesize ("base64encoded.txt"));
fclose ($fp);
echo base64_decode($str);

but if you send the string via POST or GET, you'll get this output, where the text ist messed up (copy the content of base64encoded.txt and put it behind yourscript.php?vari= ):
echo base64_decode($_GET[vari]);
 [2006-04-02 13:08 UTC]
What if you use urlencode($data) ? 
 [2006-04-02 13:18 UTC] kirlo at gmx dot de
yes, we've already tried urlencoding as an alternative and urldecode works.
but there's still the base64_decode bug when you send the data via POST or GET.
as i mentioned before, it worked under php4 and the earlier php5 versions.
 [2006-04-02 13:24 UTC]
You must use urldecode() on the data you're sending through GET/POST.
No bug here.
 [2006-04-02 13:37 UTC] kirlo at gmx dot de
ok, this time i took the string and used base64 encoding and then i urlencoded that base64 output. i sent this "double encoded" string to the server via POST/GET and there i used this script:
echo base64_decode(urldecode($_GET[vari]));

and nothing changed. the first lines are ok but then the text is messed up.

(you might think, that the base64 encoding function on my client application does not work properly, but as i mentioned before i've already tested the output with other base64 decoder and they hat no problems)
 [2006-04-02 14:13 UTC]
Don't urldecode $_GET variables and keep in mind taht most servers have an URL lenght limit.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 04:01:28 2024 UTC