mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-19 14:22:43 +08:00
170 lines
7.3 KiB
HTML
170 lines
7.3 KiB
HTML
<!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>取得服务器响应一个 HTTP 请求所发送的所有标头</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.get-headers" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">get_headers</h1>
|
||
<p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">get_headers</span> — <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">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>
|
||
] ) : <span class="type">array</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">format</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
如果将可选的 <code class="parameter">format</code> 参数设为 1,则
|
||
<span class="function"><strong>get_headers()</strong></span> 会解析相应的信息并设定数组的键名。
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
</dl>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.get-headers-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
返回包含有服务器响应一个
|
||
HTTP 请求所发送标头的索引或关联数组,如果失败则返回 <strong><code>FALSE</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>5.1.3</td>
|
||
<td>
|
||
自 PHP 5.1.3 起本函数使用默认的流上下文,其可以用 <span class="function"><a href="stream_context_get_default.html" class="function">stream_context_get_default()</a></span>
|
||
函数设定和修改。
|
||
</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-4883">
|
||
<p><strong>Example #1 <span class="function"><strong>get_headers()</strong></span> 例子</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?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">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
|
||
<div class="example-contents screen">
|
||
<div class="cdata"><pre>
|
||
Array
|
||
(
|
||
[0] => HTTP/1.1 200 OK
|
||
[1] => Date: Sat, 29 May 2004 12:28:13 GMT
|
||
[2] => Server: Apache/1.3.27 (Unix) (Red-Hat/Linux)
|
||
[3] => Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
|
||
[4] => ETag: "3f80f-1b6-3e1cb03b"
|
||
[5] => Accept-Ranges: bytes
|
||
[6] => Content-Length: 438
|
||
[7] => Connection: close
|
||
[8] => Content-Type: text/html
|
||
)
|
||
|
||
Array
|
||
(
|
||
[0] => HTTP/1.1 200 OK
|
||
[Date] => Sat, 29 May 2004 12:28:14 GMT
|
||
[Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux)
|
||
[Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
|
||
[ETag] => "3f80f-1b6-3e1cb03b"
|
||
[Accept-Ranges] => bytes
|
||
[Content-Length] => 438
|
||
[Connection] => close
|
||
[Content-Type] => text/html
|
||
)
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="example" id="example-4884">
|
||
<p><strong>Example #2 <span class="function"><strong>get_headers()</strong></span> using HEAD example</strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// By default get_headers uses a GET request to fetch the headers. If you<br />// want to send a HEAD request instead, you can do so using a stream context:<br /></span><span style="color: #0000BB">stream_context_set_default</span><span style="color: #007700">(<br /> array(<br /> </span><span style="color: #DD0000">'http' </span><span style="color: #007700">=> array(<br /> </span><span style="color: #DD0000">'method' </span><span style="color: #007700">=> </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">);<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></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 class="member"><span class="function"><a href="apache_request_headers.html" class="function" rel="rdfs-seeAlso">apache_request_headers()</a> - 获取全部 HTTP 请求头信息</span></li>
|
||
</ul>
|
||
</p>
|
||
</div>
|
||
|
||
</div></div></div></body></html> |