PHP headers_list() 函式
示例
返回已傳送的響應頭列表
<?php
setcookie("TestCookie","SomeValue");
header("X-Sample-Test: foo");
header("Content-type: text/plain");
?>
<html>
<body>
<?php
var_dump(headers_list());
?>
</body>
</html>
上面程式碼的輸出可能是
array(4)
{
[0]=> string(23) "X-Powered-By: PHP/7.1.1"
[1]=> string(19) "Set-Cookie: TestCookie=SomeValue"
[2]=> string(18) "X-Sample-Test: foo"
[3]=> string(24) "Content-type: text/plain"
}
定義和用法
headers_list() 函式返回要傳送到瀏覽器的響應頭列表。
提示: 要確定標頭是否已傳送,請使用 headers_sent() 函式。
語法
headers_list()
技術詳情
返回值 | 成功時返回一個數字索引的標頭陣列 |
---|---|
PHP 版本 | 5.0+ |
❮ PHP 網路參考