开发者

Why does this header after an echo not generate an error?

Why does this not t开发者_运维知识库hrow an error:

echo "texto em cirílico sem conversão";
echo "русская слова";
header('Content-type: text/html; charset=utf-8');

Never mind the actual text, but I did echo some text, then sent a new header, which is obviously another header?

What am I missing here?

PS. I'm basing my thoughts on the general error which pops up when you try to send a header(location.... type of thing, but you had some errors before, and the compiler screamed about headers having already been sent.


I suppose you have output buffering enabled? Check your php.ini for output_buffering. If this is switched on, all printed text will first be cached in the output buffer before being sent to STDOUT.


Try adding a flush(); after the echos and see if it makes a difference.


Doesn't header display a warning (which may be disabled) instead of error if headers already sent ? I'd add if (headers_sent()) {die('headers_sent);'} before calling header for testing.


You are sending output before you have called header. The solution to this is either fix output_buffering values or implement the use of ob_start(); and ob_end_flush();.

I hope this helps! :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜