Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 3188

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Fetches all the headers sent by the server in response to a HTTP request</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.base64-encode.html">base64_encode</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.get-meta-tags.html">get_meta_tags</a></div>
 <div class="up"><a href="ref.url.html">URL Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.get-headers" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">get_headers</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">get_headers</span> &mdash; <span class="dc-title">Fetches all the headers sent by the server in response to a HTTP request</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.get-headers-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>get_headers</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$url</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$format</code><span class="initializer"> = 0</span></span>
  ] )</div>

  <p class="para rdfs-comment">
    <span class="function"><strong>get_headers()</strong></span> returns an array with the headers sent
   by the server in response to a HTTP request.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.get-headers-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">url</code></em></span>
     <dd>

      <p class="para">
       The target URL.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">format</code></em></span>
     <dd>

      <p class="para">
       If the optional <em><code class="parameter">format</code></em> parameter is set to non-zero,
        <span class="function"><strong>get_headers()</strong></span> parses the response and sets the 
       array&#039;s keys.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.get-headers-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an indexed or associative array with the headers, or <strong><code>FALSE</code></strong> on
   failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.get-headers-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.3</td>
       <td>
        This function now uses the default stream context, which can be
        set/changed with the  <span class="function"><a href="function.stream-context-set-default.html" class="function">stream_context_set_default()</a></span>
        function.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.get-headers-examples">
 <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4081">
    <p><strong>Example #1  <span class="function"><strong>get_headers()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$url&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">get_headers</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">get_headers</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; HTTP/1.1 200 OK
    [1] =&gt; Date: Sat, 29 May 2004 12:28:13 GMT
    [2] =&gt; Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [3] =&gt; Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
    [4] =&gt; ETag: &quot;3f80f-1b6-3e1cb03b&quot;
    [5] =&gt; Accept-Ranges: bytes
    [6] =&gt; Content-Length: 438
    [7] =&gt; Connection: close
    [8] =&gt; Content-Type: text/html
)

Array
(
    [0] =&gt; HTTP/1.1 200 OK
    [Date] =&gt; Sat, 29 May 2004 12:28:14 GMT
    [Server] =&gt; Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [Last-Modified] =&gt; Wed, 08 Jan 2003 23:11:55 GMT
    [ETag] =&gt; &quot;3f80f-1b6-3e1cb03b&quot;
    [Accept-Ranges] =&gt; bytes
    [Content-Length] =&gt; 438
    [Connection] =&gt; close
    [Content-Type] =&gt; text/html
)
</pre></div>
    </div>
   </div>
   <div class="example" id="example-4082">
    <p><strong>Example #2  <span class="function"><strong>get_headers()</strong></span> using HEAD example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;By&nbsp;default&nbsp;get_headers&nbsp;uses&nbsp;a&nbsp;GET&nbsp;request&nbsp;to&nbsp;fetch&nbsp;the&nbsp;headers.&nbsp;If&nbsp;you<br />//&nbsp;want&nbsp;to&nbsp;send&nbsp;a&nbsp;HEAD&nbsp;request&nbsp;instead,&nbsp;you&nbsp;can&nbsp;do&nbsp;so&nbsp;using&nbsp;a&nbsp;stream&nbsp;context:<br /></span><span style="color: #0000BB">stream_context_set_default</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'http'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'method'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'HEAD'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;)<br />);<br /></span><span style="color: #0000BB">$headers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">get_headers</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://example.com'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.get-headers-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.apache-request-headers.html" class="function" rel="rdfs-seeAlso">apache_request_headers()</a> - Fetch all HTTP request headers</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.base64-encode.html">base64_encode</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.get-meta-tags.html">get_meta_tags</a></div>
 <div class="up"><a href="ref.url.html">URL Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>