English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP headers_list() function usage and example

PHP HTTP  Reference Manual

The headers_list() function returns the sent HTTP response headers (or those ready to be sent)

Syntax

array headers_list ( void )

Definition and Usage

 The headers_list() function returns the list of HTTP headers ready to be sent to the browser/client. Check if headers have already been sent using headers_sent().

Return value

 Returns the array of header indices.

Online Example

<?php
/* The setcookie() function will automatically add a response header */
setcookie('foo', 'bar');
/* Add custom response headers */
 Most clients will ignore it actively */
header("X-Sample-Test: foo");
/* Specify plain text content in the response */
header('Content-type: text/plain');
/* What headers will be sent? */
var_dump(headers_list());
?>

Output result:

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"
}

PHP HTTP  Reference Manual