<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Returns a list of response headers sent (or ready to send)</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.header.html">header</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.headers-sent.html">headers_sent</a></div> <div class="up"><a href="ref.network.html">Network Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.headers-list" class="refentry"> <div class="refnamediv"> <h1 class="refname">headers_list</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">headers_list</span> — <span class="dc-title">Returns a list of response headers sent (or ready to send)</span></p> </div> <div class="refsect1 description" id="refsect1-function.headers-list-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>headers_list</strong></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>headers_list()</strong></span> 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 <span class="function"><a href="function.headers-sent.html" class="function">headers_sent()</a></span>. </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.headers-list-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a numerically indexed array of headers. </p> </div> <div class="refsect1 examples" id="refsect1-function.headers-list-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4486"> <p><strong>Example #1 Examples using <span class="function"><strong>headers_list()</strong></span></strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">/* setcookie() will add a response header on its own */<br /></span><span style="color: #0000BB">setcookie</span><span style="color: #007700">(</span><span style="color: #DD0000">'foo'</span><span style="color: #007700">, </span><span style="color: #DD0000">'bar'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Define a custom response header<br /> This will be ignored by most clients */<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"X-Sample-Test: foo"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* Specify plain text content in our response */<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-type: text/plain'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/* What headers are going to be sent? */<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">headers_list</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> 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" } </pre></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.headers-list-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> Headers will only be accessible and output when a SAPI that supports them is in use. </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.headers-list-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.headers-sent.html" class="function" rel="rdfs-seeAlso">headers_sent()</a> - Checks if or where headers have been sent</span></li> <li class="member"> <span class="function"><a href="function.header.html" class="function" rel="rdfs-seeAlso">header()</a> - Send a raw HTTP header</span></li> <li class="member"> <span class="function"><a href="function.setcookie.html" class="function" rel="rdfs-seeAlso">setcookie()</a> - Send a cookie</span></li> <li class="member"> <span class="function"><a href="function.apache-response-headers.html" class="function" rel="rdfs-seeAlso">apache_response_headers()</a> - Fetch all HTTP response headers</span></li> <li class="member"> <span class="function"><a href="function.http-response-code.html" class="function" rel="rdfs-seeAlso">http_response_code()</a> - Get or Set the HTTP response code</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.header.html">header</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.headers-sent.html">headers_sent</a></div> <div class="up"><a href="ref.network.html">Network Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>