首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

headers_list

(PHP 5, PHP 7)

headers_list — Returns a list of response headers sent (or ready to send)

Description

代码语言:javascript
复制
array headers_list ( void )

headers_list() will return a list of headers to be sent to the browser / client. To determine whether or not these headers have been sent yet, use headers_sent().

Return Values

Returns a numerically indexed array of headers.

Examples

Example #1 Examples using headers_list()

代码语言:javascript
复制
<?php

/* setcookie() will add a response header on its own */
setcookie('foo', 'bar');

/* Define a custom response header
   This will be ignored by most clients */
header("X-Sample-Test: foo");

/* Specify plain text content in our response */
header('Content-type: text/plain');

/* What headers are going to be sent? */
var_dump(headers_list());

?>

The above example will output:

代码语言:javascript
复制
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"
}

Notes

Note: Headers will only be accessible and output when a SAPI that supports them is in use.

See Also

  • headers_sent() - Checks if or where headers have been sent
  • header() - Send a raw HTTP header
  • setcookie() - Send a cookie
  • apache_response_headers() - Fetch all HTTP response headers
  • http_response_code() - Get or Set the HTTP response code

← header

headers_sent →

代码语言:txt
复制
 © 1997–2017 The PHP Documentation Group

Licensed under the Creative Commons Attribution License v3.0 or later.

扫码关注腾讯云开发者

领取腾讯云代金券