headers_list() - php 网络函数
headers_list()
(PHP 5, PHP 7)
返回已发送的 HTTP 响应头(或准备发送的)
说明
headers_list(void): arrayheaders_list()会返回准备发送给浏览器/客户端的 HTTP 头列表。检测这些头是否已经发送,使用headers_sent()。
返回值
返回数字索引的头数组。
范例
使用headers_list()的例子
以上例程会输出:
array(4) { [0]=> string(23) "X-Powered-By: PHP/5.1.3" [1]=> string(19) "Set-Cookie: foo=bar" [2]=> string(18) "X-Sample-Test: foo" [3]=> string(24) "Content-type: text/plain" }
注释
Note:数据头只会在SAPI支持时得到处理和输出。
参见
headers_sent()
检测 HTTP 头是否已经发送header()
发送原生 HTTP 头setcookie()
发送 Cookieapache_response_headers()
获得全部 HTTP 响应头信息http_response_code()
获取/设置响应的 HTTP 状态码
note that it does not return the status header Array ( [0] => X-Powered-By: PHP/5.4.7 [1] => foo: bar [2] => a: b )
This function won't work for when you're running PHP from the command line. If will always return an empty array. This can be an issue when testing your project using PHPUnit or Codeception. To solve this, install the xdebug extension and use `xdebug_get_headers` when on the cli.
Function to check if a particular header has been added to the list:
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)