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

PHP Basic Tutorial

PHP Advanced 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

 headers_list() will return the HTTP response headers (or those ready to be sent) to the browser/Client HTTP header list. Check if these headers have been sent using headers_sent().

Return value

 Returns an array of header indices.

Online examples

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

Output result:

array(4) {
  [0]=>
  string(23) X-Powered-By: PHP/5.1.3
  [1return
  string(19) Set-Cookie: foo=bar"
  [2return
  string(18) X-Sample-Test: foo"
  [3return
  string(24) Content-type: text/plain"
}

PHP HTTP Reference Manual