header_register_callback() 函數(shù)調(diào)用一個 header 函數(shù)。
eader_register_callback ( callable $callback )
注冊一個函數(shù),在 PHP 開始發(fā)送輸出時調(diào)用。
PHP 準(zhǔn)備好所有響應(yīng)頭,在發(fā)送內(nèi)容之前執(zhí)行 callback,創(chuàng)建了一個發(fā)送響應(yīng)頭的操作窗口。
注意: header_register_callback() 是在頭即將發(fā)送前執(zhí)行的, 所以本函數(shù)的任意內(nèi)容輸出都會打斷輸出過程。
成功時返回 TRUE, 或者在失敗時返回 FALSE。
| 序號 | 參數(shù)和說明 |
|---|---|
| 1 | callback 在頭發(fā)送前調(diào)用函數(shù)。 它沒有參數(shù),返回的值也會被忽略。 |
<?php
header('Content-Type: text/plain');
header('X-Test: foo');
function foo() {
foreach (headers_list() as $header) {
if (strpos($header, 'X-Powered-By:') !== false) {
header_remove('X-Powered-By');
}
header_remove('X-Test');
}
}
$result = header_register_callback('foo');
echo "a";
?>輸出結(jié)果
Content-Type: text/plain a