header_remove
刪除之前設置的HTTP 頭
header_remove()
函數移除先前通過header()
函數設置的HTTP 標頭。
刪除特定標頭:
<?php header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ) ; header ( "Cache-Control: no-cache" ) ; header ( "Pragma: no-cache" ) ; header_remove ( "Pragma" ) ; ?>
刪除所有先前設置的標頭:
<?php header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ) ; header ( "Cache-Control: no-cache" ) ; header ( "Pragma: no-cache" ) ; header_remove ( ) ; ?>
在這個示例中,所有通過header()
函數先前設置的HTTP 標頭( "Expires"
、 "Cache-Control"
和"Pragma"
)都將通過調用header_remove()
函數(不帶參數)而被移除。這意味著HTTP 響應將不包含這些標頭信息。這在某些情況下可能很有用,特別是當你希望重置或清除先前設置的標頭信息時。但是,請注意, header_remove()
函數不會影響PHP 已經發送給客戶端的標頭;它只影響在函數調用時仍處於待處理狀態的標頭。
header_remove ( headername )
參數 | 描述 |
---|---|
headername |
可選。指定要刪除的標頭名稱。 如果省略,則刪除所有先前設置的標頭。 |