PHP headers_list() 函数
定义和用法
headers_list() 函数返回要发送到浏览器的响应标头列表。
提示:如需确定标头是否已发送,请使用 headers_sent() 函数。
实例
返回已发送的响应标头列表:
<?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()
技术细节
| 返回值: | 成功时返回数字索引的标头数组。 |
|---|---|
| PHP 版本: | 5.0+ |