TwelvestoneBack End

PHP - Warning: Cannot modify header information - headers already sent


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
DontBogartMe
 
2010-02-16

I'm trying to set up a little PHP script fromhttp://www.alivepdf.org/ so that my Flash can output to PDF... but I'm having trouble with it.

Here's the script: <? $method = $GET['method']; $name = $GET['name'];

if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
    // get bytearray
    $pdf = $GLOBALS["HTTP_RAW_POST_DATA"];
    // add headers for download dialog-box
    header('Content-Type: application/pdf');
    header('Content-Length: '.strlen($pdf));
    header('Content-disposition:'.$method.'; filename="'.$name.'"');
    echo $pdf;
} else {
    echo 'An error occured.';
}

?>

And here's the output of that, just run by directly: > Warning: Cannot modify header information - headers already sent by (output started at /home/test/public_html/create_pdf.php:1) in /home/test/public_html/create_pdf.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at /home/test/public_html/create_pdf.php:1) in /home/test/public_html/create_pdf.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at /home/test/public_html/create_pdf.php:1) in /home/test/public_html/create_pdf.php on line 10 then it dumps out the PDF in text.

To test I've tried moving the header line to line #1 and it still throws the error - which makes me think that something else outside of my script is sending header info before my script starts. I'm pretty rusty with PHP - can anyone throw me a line here?

The server's running PHP 5.2.11, dunno if this is any use but this is the PHPINFO section HTTP Headers Information: HTTP Request Headers HTTP Request GET /******/phpinfo.php HTTP/1.1 Host ************.com Connection keep-alive User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.89 Safari/532.5 Accept application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,/;q=0.5 Accept-Encoding gzip,deflate,sdch Accept-Language en-GB,es-ES;q=0.8,es;q=0.6 Accept-Charset ISO-8859-1,utf-8;q=0.7,;q=0.3 HTTP Response Headers X-Powered-By PHP/5.2.11 Keep-Alive timeout=15, max=100 Connection Keep-Alive Transfer-Encoding chunked Content-Type text/html

Technomancer
 
2010-02-16

This normally happens because you have already sent output to the browser.

So the header info has already been received and some/all of the body content. This can sometimes be as innocuous as a blank line before your opening <?php tag.

Is there any html prior to your php script?

DontBogartMe
 
2010-02-16

no, there's nothing in there, no white space no html, just what I posted up there.

using headers_list() on line 1 I can see something IS dumping out headers before my script starts: > array(2) { [0]=> string(24) "X-Powered-By: PHP/5.2.11" [1]=> string(23) "Content-type: text/html" }

Technomancer
 
2010-02-16

Sorry DBM, didn't read your post in full.

How is the php script being called?

You could try using the output buffer, place ob_start() at the beginning of the script and ob_flush() as the end.

DontBogartMe
 
2010-02-16

ah Notepad2 you little beauty. I read someone mentioned that UTF-8 with BOF was messing up his script, so I opened it up in Notepad2, changed the encoding from UTF-8 with Signature to just UTF-8 and voilá - it works k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

PHP - Warning: Cannot modify header information - headers already sent