PHP Function Reference

PHP header_list() Function



The PHP header_list() function returns a list of headers to be sent to the browser / client. To determine whether or not these headers have been sent yet, headers_sent() function can be used.

Syntax

header_list()

Parameters

No parameter is required.

Return Value

Returns a numerically indexed array of headers.

Example: header_list() example

The example below shows the usage of header_list() function.

<?php
//setcookie() function is used to add a response header
setcookie("TestCookie","SomeValue");

//defining the response header
header("test: alphacodingskills");

//specifing plain text content in the response
header("Content-Type: text/plain; charset=UTF-8");

//displaying the array returned by 
//the headers_list() function
var_dump(headers_list());
?>

The output of the above code will be:

array(3) {
  [0]=>
  string(32) "Set-Cookie: TestCookie=SomeValue"
  [1]=>
  string(23) "test: alphacodingskills"
  [2]=>
  string(39) "Content-Type: text/plain; charset=UTF-8"
}

❮ PHP Network Reference