<?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 => 'ru',
  ),
  'this' => 
  array (
    0 => 'function.get-headers.php',
    1 => 'get_headers',
    2 => 'Возвращает все заголовки из ответа сервера на HTTP-запрос',
  ),
  'up' => 
  array (
    0 => 'ref.url.php',
    1 => 'Функции URL',
  ),
  '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' => 'ru',
    '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">Возвращает все заголовки из ответа сервера на HTTP-запрос</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.get-headers-description">
  <h3 class="title">Описание</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> возвращает массив с заголовками из ответа
   сервера на HTTP-запрос.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.get-headers-parameters">
  <h3 class="title">Список параметров</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">url</code></dt>
     <dd>
      <p class="para">
       Целевой URL.
      </p>
     </dd>
    
    
     <dt><code class="parameter">associative</code></dt>
     <dd>
      <p class="para">
       Если необязательный параметр <code class="parameter">associative</code>
       установлен в ненулевое значение, <span class="function"><strong>get_headers()</strong></span>
       разберёт ответ сервера и установит ключи для возвращаемого массива.
      </p>
     </dd>
    
    
     <dt><code class="parameter">context</code></dt>
     <dd>
      <p class="para">
       Корректный контекст ресурса, созданный с помощью
       <span class="function"><a href="function.stream-context-create.php" class="function">stream_context_create()</a></span> или <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, чтобы
       использовать контекст ресурса по умолчанию.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.get-headers-returnvalues">
  <h3 class="title">Возвращаемые значения</h3>
  <p class="para">
   Возвращает индексированный или ассоциативный массив с заголовками ответа
   или <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> при возникновении ошибки.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.get-headers-changelog">
  <h3 class="title">Список изменений</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версия</th>
       <th>Описание</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        Тип параметра <code class="parameter">associative</code> был изменён с целого числа (<span class="type"><a href="language.types.integer.php" class="type int">int</a></span>) на логическое значение (<span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span>).
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        Добавлен параметр <code class="parameter">context</code>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.get-headers-examples">
 <h3 class="title">Примеры</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Пример #1 Пример использования <span class="function"><strong>get_headers()</strong></span></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>
 Вывод приведённого примера будет похож на:
</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>Пример #2 Пример использования запроса HEAD в функции<span class="function"><strong>get_headers()</strong></span></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">// По умолчанию функция get_headers использует GET-запрос для получения заголовков. Если<br />// вы хотите вместо него отправить HEAD-запрос, то это можно сделать, используя контекста потока:<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">Смотрите также</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> - Получает список заголовков HTTP-запроса</span></li>
   </ul>
  </p>
 </div>


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