<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.network.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.http-response-code.php',
    1 => 'http_response_code',
    2 => 'HTTP レスポンスコードを取得または設定',
  ),
  'up' => 
  array (
    0 => 'ref.network.php',
    1 => 'ネットワーク 関数',
  ),
  'prev' => 
  array (
    0 => 'function.http-get-last-response-headers.php',
    1 => 'http_get_last_response_headers',
  ),
  'next' => 
  array (
    0 => 'function.inet-ntop.php',
    1 => 'inet_ntop',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'ja',
    'path' => 'reference/network/functions/http-response-code.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.http-response-code" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">http_response_code</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.4.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">http_response_code</span> &mdash; <span class="dc-title">HTTP レスポンスコードを取得または設定</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.http-response-code-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>http_response_code</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$response_code</code><span class="initializer"> = 0</span></span>): <span class="type"><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></span></div>

  <p class="para rdfs-comment">
   HTTP レスポンスのステータスコードを取得したり設定したりします。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.http-response-code-parameters">
  <h3 class="title">パラメータ</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">response_code</code></dt>
     <dd>
      <p class="para">
       オプションの <code class="parameter">response_code</code> は、レスポンスコードを設定します。
      </p>
     </dd>
       
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.http-response-code-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   <code class="parameter">response_code</code> を指定した場合は、変更前に設定されていたステータスコードを返します。
   <code class="parameter">response_code</code> を省略した場合は、現在のステータスコードを返します。
   どちらの場合でも、Web サーバー環境におけるデフォルトのステータスコードは
   <code class="literal">200</code> です。
  </p>
  <p class="para">
   <code class="parameter">response_code</code> が省略されており、
   かつ Web サーバー環境以外 (CLI アプリケーションなど) で実行した場合には、<strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
   <code class="parameter">response_code</code> を指定して、
   かつ Web サーバー環境以外 (CLI アプリケーションなど) で実行した場合
   (ただし、事前にレスポンスのステータスが設定されていない場合に限る) には、<strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> を返します。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.http-response-code-examples">
  <h3 class="title">例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>例1 Web サーバー環境における <span class="function"><strong>http_response_code()</strong></span> の使用例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// 現在のレスポンスコードを取得して、新しいコードを設定します<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">http_response_code</span><span style="color: #007700">(</span><span style="color: #0000BB">404</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// 新しいレスポンスコードを取得します<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">http_response_code</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">int(200)
int(404)</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>例2 CLI 環境における <span class="function"><strong>http_response_code()</strong></span> の使用例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// 現在のデフォルトのレスポンスコードを取得します<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">http_response_code</span><span style="color: #007700">());<br /><br /></span><span style="color: #FF8000">// レスポンスコードを設定します<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">http_response_code</span><span style="color: #007700">(</span><span style="color: #0000BB">201</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// 新しいレスポンスコードを取得します<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">http_response_code</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">bool(false)
bool(true)
int(201)</pre>
</div>
    </div>
   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.http-response-code-seealso">
  <h3 class="title">参考</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.header.php" class="function" rel="rdfs-seeAlso">header()</a> - 生の HTTP ヘッダを送信する</span></li>
    <li><span class="function"><a href="function.headers-list.php" class="function" rel="rdfs-seeAlso">headers_list()</a> - 送信した (もしくは送信される予定の) レスポンスヘッダの一覧を返す</span></li>
   </ul>
  </p>
 </div>
 


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