Edit report at https://bugs.php.net/bug.php?id=41491&edit=1

 ID:                 41491
 Comment by:         dosergio at ig dot com dot br
 Reported by:        jeff at pointhere dot net
 Summary:            header() adds extra x'200A' space/LF to start of
                     file
 Status:             Not a bug
 Type:               Bug
 Package:            HTTP related
 Operating System:   Sun OS 5.10 (Solaris 10)
 PHP Version:        5.2.2
 Block user comment: N
 Private report:     N

 New Comment:

I have a similar problem.
If I use:

header("Content-type: application/json");
to a page that will serve actual json code, the response gains 4 spaces (char 
32) at the beginning. Ok, this do not break the script, json still works but I 
am questioning the fidelity of content, as those 4 spaces do not exist in 
original json code but appears in the output when I set the header.

 If I comment header line, the spaces disappear immediatelly. Already tried to 
replace quotes by apostrofes (') but don't work either.
I suspect that header function is adding space internally.


Previous Comments:
------------------------------------------------------------------------
[2007-05-28 20:10:13] tony2...@php.net

.

------------------------------------------------------------------------
[2007-05-27 22:18:09] jeff at pointhere dot net

THAT DID IT!!  I then started experimenting with the code - I took out all of 
the code that had any variables and it worked.  As soon as I added them in it 
did not.  Then I changed the code to work with apostrophes rather than quotes 
and put the variables back in with a concatonation and it worked!  I hope this 
makes sense and leads to a fix using the quotes and replacable variables. This 
code works as expected and you can color me thrilled:

        
// Start sending the file
ob_start();
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Transfer-Encoding: 7bit');
echo($cardprint_file);
ob_end_flush();

Thank you so much for pointing me down the path that led me to a work-around 
and a working program!!!

   Jeff

------------------------------------------------------------------------
[2007-05-27 17:50:20] il...@php.net

Can you try leaving header() calls with static parameters (no embeded 
variables) and see if you still get the extra chars?

------------------------------------------------------------------------
[2007-05-24 15:50:34] jeff at pointhere dot net

Description:
------------
When using the header() function to prepend a text file so that a user can save 
a downloaded file, the resulting file has two extra characters on the front of 
the file (hex '200A' - space and line-feed).  When header() functions are 
removed, the file appears to load into the browser correctly.

Reproduce code:
---------------
// Start sending the file
ob_start();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: text/plain");
header("Content-Length: " . $filesize);
header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
header("Content-Transfer-Encoding: 7bit");
echo($cardprint_file);
ob_end_flush();
exit;


Expected result:
----------------
The user's browser should open a window that asks to Open, Save or Cancel the 
download.  When saving or opening the file the contents of $cardprint_file 
should be the ONLY contents (the contents were verified to be correct with the 
var_dump command).

Actual result:
--------------
The first two characters in the file (which translate to a blank line) are an 
ASCII hex 20 (space) and an ASCII hex 0A (Line feed).


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=41491&edit=1

Reply via email to