<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.url.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.get-headers.php',
    1 => 'get_headers',
    2 => 'Ruft alle Header ab, die der Server als Antwort auf einen HTTP-Request versendet',
  ),
  'up' => 
  array (
    0 => 'ref.url.php',
    1 => 'URL Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.base64-encode.php',
    1 => 'base64_encode',
  ),
  'next' => 
  array (
    0 => 'function.get-meta-tags.php',
    1 => 'get_meta_tags',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'de',
    'path' => 'reference/url/functions/get-headers.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.get-headers" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">get_headers</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">get_headers</span> &mdash; <span class="dc-title">
   Ruft alle Header ab, die der Server als Antwort auf einen HTTP-Request versendet
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.get-headers-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>get_headers</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$url</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$associative</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span></span> <code class="parameter">$context</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>get_headers()</strong></span> gibt ein Array zurück, das die vom Server
   in seiner Antwort auf eine HTTP-Anfrage gesendeten Header enthält.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.get-headers-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">url</code></dt>
     <dd>
      <p class="para">
       Die Ziel-URL.
      </p>
     </dd>
    
    
     <dt><code class="parameter">associative</code></dt>
     <dd>
      <p class="para">
       Wenn der optionale Parameter <code class="parameter">associative</code> auf
       <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> gesetzt wird, parst
       <span class="function"><strong>get_headers()</strong></span> die Serverantwort und setzt die
       entsprechenden Schlüssel des Arrays.
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">
       Eine gültige Kontextressource, die mit
       <span class="function"><a href="function.stream-context-create.php" class="function">stream_context_create()</a></span> erstellt wurde oder <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>
       um den Standard-Kontext zu verwenden.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.get-headers-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   Gibt ein indexbasiertes oder ein assoziatives Array zurück, das die
   übermittelten Header enthält. Im Fehlerfall wird <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> zurückgegeben.
  </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>Beschreibung</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        Der Typ des Parameters <code class="parameter">associative</code> wurde von
        <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> in <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> geändert.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        Der Parameter <code class="parameter">context</code> wurde hinzugefügt.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.get-headers-examples">
 <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>get_headers()</strong></span>-Beispiel</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$url </span><span style="color: #007700">= </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">, </span><span style="color: #0000BB">true</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Das oben gezeigte Beispiel erzeugt
eine ähnliche Ausgabe wie:</p></div>
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">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-2">
    <p><strong>Beispiel #2 <span class="function"><strong>get_headers()</strong></span>-Beispiel unter Verwendung von HEAD</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">// Standardmäßig verwendet get_headers einen GET-Request um die Header<br />// abzurufen. Wenn stattdessen ein HEAD-Request durchgeführt werden soll,<br />// muss ein Stream-Kontext verwendet werden:<br /></span><span style="color: #0000BB">$context </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(<br />    [<br />        </span><span style="color: #DD0000">'http' </span><span style="color: #007700">=&gt; array(<br />            </span><span style="color: #DD0000">'method' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">'HEAD'<br />        </span><span style="color: #007700">)<br />    ]<br />);<br /></span><span style="color: #0000BB">$headers </span><span style="color: #007700">= </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">, </span><span style="color: #0000BB">false</span><span style="color: #007700">, </span><span style="color: #0000BB">$context</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">Siehe auch</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.apache-request-headers.php" class="function" rel="rdfs-seeAlso">apache_request_headers()</a> - Liefert alle HTTP-Requestheader</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>