Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I cancel it if the header is sent?

Status
Not open for further replies.

digitalroamer

Programmer
Jan 4, 2005
6
CA
I check the header_sent, and it says TRUE. but the header_list() is a undefined function. And after that, whatever header I want to send causes parse errors.
Is it an apache question? I'm using php 4.23, apache 1.3.27 /NT.

Thanks.
 
Make sure that there is nothing echoed to the screen before the php, as in no code between the ?> and <? tags and no spaces before the call to header functions.

--Chessbot

"In that blessed region of Four Dimensions, shall we linger on the threshold of the Fifth, and not enter therein? Ah, no! [...] Then, yielding to our intellectual onset, the gates of the Sixth Dimension shall fly open; after that a Seventh, and then an Eighth -- --" Flatland, A. Square (E. A. Abbott)
 
In addition, my error messages include the file and line which caused the headers to be sent.
 
this is exactly what I did in the file.

<html>
<body>
<?header("Content-type : image/png");
if(!headers_sent())
{
header("Content-type : image/png");
}
else
{
var_dump(headers_list());
}
$idfer=imagecreate(600,200);

$red=imagecolorallocate($idfer,255,0,0);

imagefill($idfer,0,0,$red);

imagepng($idfer);
imagedestroy($idfer);
?>
</body></html>

and the errors are :

Warning: Cannot add header information - headers already sent by (output started at e:\phpdev\phpdev\testdraw.php:3) in e:\phpdev\phpdev\testdraw.php on line 3

Fatal error: Call to undefined function: headers_list() in e:\phpdev\phpdev\testdraw.php on line 10

and the phpinfo says gd support is enable.
 
As chessbot said it, nothing must be sent to the browser before the headers. Your script outputs <html><body> before the first header is sent and that's what generates the error. Once again, header invocation must be made before any output is made. Completely unrelated, your output will be a .png image, thus html tags have no place there.
 
but nothing's changed when I deleted the <html><body>. Now the header is in the very beginning, but still have the same problem. and another fatal error is the function headers_list() is undefined. So anywhere I may change the header?

Thanks advanced.
 
Make sure you have no blank lines, spaces, or other whitespace before your <?php tag. Even a blank line will cause this error.

You're running PHP 4.23. The online manual states that headers_list() is available only in PHP 5.





Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thank you.
the problem is I have a space between <? and php. It's ok when I delete it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top