13

タイトルは自明です。

PHP にはかなりの経験がありますが、関数が と の間でどのようにheader機能するかはわかりません。ob_start()ob_end_clean()

このことを考慮:

ob_start();

echo "Some content";
header('X-Example-Header: foo');
echo "Some more content";

$output = ob_get_contents();
ob_end_clean();

echo $output;

Does the header function ignore the output buffering, and thus all headers get sent before the content because it is echoed after the header call?

Or does it work some other way?

4

1 に答える 1

19

header()実際に出力バッファリングを無視します。出力バッファリングを使用する理由の 1 つは、応答がバッファリングされるため、HTTP ヘッダーを「順不同で」送信できるようにするためです。何らかの種類の出力を送信した後は、HTTP ヘッダーを送信できません (その出力がバッファリングされていない限り)。

于 2010-06-24T15:03:16.400 に答える