cvs: phpdoc-ja /reference/http reference.xml /reference/http/functions header.xml headers-list.xml headers-sent.xml setcookie.xml setrawcookie.xml
/reference/network/functions header.xml headers-list.xml headers-sent.xml setcookie.xml setrawcookie.xml

From: Date: Thu, 27 Jul 2006 03:32:04 +0000
Subject: cvs: phpdoc-ja /reference/http reference.xml /reference/http/functions header.xml headers-list.xml headers-sent.xml setcookie.xml setrawcookie.xml
/reference/network/functions header.xml headers-list.xml headers-sent.xml setcookie.xml setrawcookie.xml
Groups: php.doc.ja 
Request: Send a blank email to doc-ja+get-1586@lists.php.net to get a copy of this message
takagi Thu Jul 27 03:32:04 2006 UTC Added files: /phpdoc-ja/reference/network/functions setrawcookie.xml setcookie.xml headers-sent.xml headers-list.xml header.xml Removed files: /phpdoc-ja/reference/http/functions setrawcookie.xml setcookie.xml headers-sent.xml headers-list.xml header.xml Modified files: /phpdoc-ja/reference/http reference.xml Log: sync with en.

http://cvs.php.net/viewvc.cgi/phpdoc-ja/reference/http/reference.xml?r1=1.5&r2=1.6&diff_format=u Index: phpdoc-ja/reference/http/reference.xml diff -u phpdoc-ja/reference/http/reference.xml:1.5 phpdoc-ja/reference/http/reference.xml:1.6 --- phpdoc-ja/reference/http/reference.xml:1.5 Mon Sep 5 11:34:06 2005 +++ phpdoc-ja/reference/http/reference.xml Thu Jul 27 03:32:04 2006 @@ -1,52 +1,183 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- $Revision: 1.5 $ --> -<!-- EN-Revision: 1.8 Maintainer: hirokawa Status: ready --> -<!-- CREDITS: shimooka --> +<!-- $Revision: 1.6 $ --> +<!-- EN-Revision: 1.10 Maintainer: hirokawa Status: ready --> +<!-- CREDITS: shimooka,takagi --> <!-- Purpose: basic.php --> -<!-- Membership: core --> +<!-- Membership: pecl --> - <reference id="ref.http"> - <title>HTTP 関連の関数</title> - <titleabbrev>HTTP</titleabbrev> +<reference id="ref.http"> + <title>HTTP</title> + <titleabbrev>http</titleabbrev> - <partintro> - <section id="http.intro"> + <partintro> + <sect1 id="http.intro"> &reftitle.intro; - <para> - 以下の関数は、リモートブラウザに送り返される出力を、HTTPプロトコル - レベルで制御するためのものです。 - </para> - </section> - - <section id="http.requirements"> - &reftitle.required; - &no.requirement; - </section> - - <section id="http.installation"> - &reftitle.install; - &no.install; - </section> - - <section id="http.configuration"> - &reftitle.runtime; - &no.config; - </section> - - <section id="http.resources"> - &reftitle.resources; - &no.resource; - </section> - - <section id="http.constants"> - &reftitle.constants; - &no.constants; - </section> - </partintro> + <simpara> + この HTTP 拡張モジュールの狙いは、PHP + アプリケーションのために便利で強力な機能を提供することです。 + </simpara> + <simpara> + HTTP の URL、日付、リダイレクト、ヘッダおよびメッセージを + 使いやすくし、クライアントの希望する言語および文字セットの + ネゴシエーション手段を提供します。 + また、任意のデータを送信する際にキャッシュやリジュームの機能を + もたせることができます。 + </simpara> + <simpara> + CURL サポート込みでビルドされている場合は、 + 強力なリクエスト機能を提供します。PHP 5 以降では、 + 複数のリクエストを平行して実行することができます。 + </simpara> + <simpara> + このマニュアルでは、API リファレンスに加えて + インストールや設定の方法、定義済みのグローバル定数などを + 以下の節で説明しています。 + </simpara> + <simplelist> + <member><link linkend="http.install">インストール</link></member> + <member><link linkend="http.configuration">設定</link></member> + <member><link linkend="http.constants">グローバル定数</link></member> + </simplelist> + </sect1> + + <sect1> + <title>クラス</title> + <simplelist> + <member><link linkend="http.HttpMessage"><classname>HttpMessage</classname></link></member> + <member><link linkend="http.HttpQueryString"><classname>HttpQueryString</classname></link></member> + <member><link linkend="http.HttpDeflateStream"><classname>HttpDeflateStream</classname></link></member> + <member><link linkend="http.HttpInflateStream"><classname>HttpInflateStream</classname></link></member> + <member><link linkend="http.HttpRequest"><classname>HttpRequest</classname></link></member> + <member><link linkend="http.HttpRequestPool"><classname>HttpRequestPool</classname></link></member> + </simplelist> + </sect1> + + <sect1> + <title>関数</title> + <sect2> + <title>組み込みの関数</title> + <simpara> + このページで説明している以外に、組み込みの HTTP 関連関数が + <link linkend="ref.network">ネットワーク関数</link> + に挙げられています。 + </simpara> + <simpara> + 以下の関数は、HTTP モジュールを必要としません。 + <function>header</function>、<function>headers_list</function>、<function>headers_sent</function>、 + <function>setcookie</function> &listendand; <function>setrawcookie</function>。 + </simpara> + </sect2> + <sect2> + <title>キャッシュ</title> + <simplelist> + <member><link linkend="function.http-cache-etag"><function>http_cache_etag</function></link></member> + <member><link linkend="function.http-cache-last-modified"><function>http_cache_last_modified</function></link></member> + </simplelist> + </sect2> + <sect2> + <title>エンコーディング</title> + <simplelist> + <member><link linkend="function.http-chunked-decode"><function>http_chunked_decode</function></link></member> + <member><link linkend="function.http-deflate"><function>http_deflate</function></link></member> + <member><link linkend="function.http-inflate"><function>http_inflate</function></link></member> + </simplelist> + </sect2> + <sect2> + <title>雑多な関数</title> + <simplelist> + <member><link linkend="function.http-build-cookie"><function>http_build_cookie</function></link></member> + <member><link linkend="function.http-date"><function>http_date</function></link></member> + <member><link linkend="function.http-get-request-body-stream"><function>http_get_request_body_stream</function></link></member> + <member><link linkend="function.http-get-request-body"><function>http_get_request_body</function></link></member> + <member><link linkend="function.http-get-request-headers"><function>http_get_request_headers</function></link></member> + <member><link linkend="function.http-match-etag"><function>http_match_etag</function></link></member> + <member><link linkend="function.http-match-modified"><function>http_match_modified</function></link></member> + <member><link linkend="function.http-match-request-header"><function>http_match_request_header</function></link></member> + <member><link linkend="function.http-support"><function>http_support</function></link></member> + </simplelist> + </sect2> + <sect2> + <title>ネゴシエーション</title> + <simplelist> + <member><link linkend="function.http-negotiate-charset"><function>http_negotiate_charset</function></link></member> + <member><link linkend="function.http-negotiate-ctype"><function>http_negotiate_ctype</function></link></member> + <member><link linkend="function.http-negotiate-language"><function>http_negotiate_language</function></link></member> + </simplelist> + </sect2> + <sect2> + <title>出力ハンドラ</title> + <simplelist> + <member><link linkend="function.ob-deflatehandler"><function>ob_deflatehandler</function></link></member> + <member><link linkend="function.ob-etaghandler"><function>ob_etaghandler</function></link></member> + <member><link linkend="function.ob-inflatehandler"><function>ob_inflatehandler</function></link></member> + </simplelist> + </sect2> + <sect2> + <title>パーサ</title> + <simplelist> + <member><link linkend="function.http-parse-cookie"><function>http_parse_cookie</function></link></member> + <member><link linkend="function.http-parse-headers"><function>http_parse_headers</function></link></member> + <member><link linkend="function.http-parse-message"><function>http_parse_message</function></link></member> + <member><link linkend="function.http-parse-params"><function>http_parse_params</function></link></member> + </simplelist> + </sect2> + <sect2> + <title>リクエスト</title> + <simplelist> + <member><link linkend="function.http-get"><function>http_get</function></link></member> + <member><link linkend="function.http-head"><function>http_head</function></link></member> + <member><link linkend="function.http-post-data"><function>http_post_data</function></link></member> + <member><link linkend="function.http-post-fields"><function>http_post_fields</function></link></member> + <member><link linkend="function.http-put-data"><function>http_put_data</function></link></member> + <member><link linkend="function.http-put-file"><function>http_put_file</function></link></member> + <member><link linkend="function.http-put-stream"><function>http_put_stream</function></link></member> + <member><link linkend="function.http-request-body-encode"><function>http_request_body_encode</function></link></member> + <member><link linkend="function.http-request-method-exists"><function>http_request_method_exists</function></link></member> + <member><link linkend="function.http-request-method-name"><function>http_request_method_name</function></link></member> + <member><link linkend="function.http-request-method-register"><function>http_request_method_register</function></link></member> + <member><link linkend="function.http-request-method-unregister"><function>http_request_method_unregister</function></link></member> + <member><link linkend="function.http-request"><function>http_request</function></link></member> + </simplelist> + </sect2> + <sect2> + <title>レスポンス</title> + <simplelist> + <member><link linkend="function.http-redirect"><function>http_redirect</function></link></member> + <member><link linkend="function.http-send-content-disposition"><function>http_send_content_disposition</function></link></member> + <member><link linkend="function.http-send-content-type"><function>http_send_content_type</function></link></member> + <member><link linkend="function.http-send-data"><function>http_send_data</function></link></member> + <member><link linkend="function.http-send-file"><function>http_send_file</function></link></member> + <member><link linkend="function.http-send-last-modified"><function>http_send_last_modified</function></link></member> + <member><link linkend="function.http-send-status"><function>http_send_status</function></link></member> + <member><link linkend="function.http-send-stream"><function>http_send_stream</function></link></member> + <member><link linkend="function.http-throttle"><function>http_throttle</function></link></member> + </simplelist> + </sect2> + <sect2> + <title>URL</title> + <simplelist> + <member><link linkend="function.http-build-str"><function>http_build_str</function></link></member> + <member><link linkend="function.http-build-url"><function>http_build_url</function></link></member> + </simplelist> + </sect2> + </sect1> + + </partintro> + + &reference.http.install; + &reference.http.configuration; + &reference.http.constants; + &reference.http.HttpMessage; + &reference.http.HttpQueryString; + &reference.http.HttpDeflateStream; + &reference.http.HttpInflateStream; + &reference.http.HttpRequest; + &reference.http.HttpRequestPool; + &reference.http.HttpResponse; + &reference.http.functions; -&reference.http.functions; +</reference> - </reference> <!-- Keep this comment at the end of the file Local variables: mode: sgml @@ -67,4 +198,3 @@ vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> - http://cvs.php.net/viewvc.cgi/phpdoc-ja/reference/network/functions/setrawcookie.xml?view=markup&rev=1.1 Index: phpdoc-ja/reference/network/functions/setrawcookie.xml +++ phpdoc-ja/reference/network/functions/setrawcookie.xml <?xml version="1.0" encoding="utf-8"?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.1 Maintainer: takagi Status: ready --> <refentry id="function.setrawcookie"> <refnamediv> <refname>setrawcookie</refname> <refpurpose>値を URL エンコードせずにクッキーを送信する</refpurpose> </refnamediv> <refsect1> <title>説明</title> <methodsynopsis> <type>bool</type><methodname>setrawcookie</methodname> <methodparam><type>string</type><parameter>name</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>value</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>expire</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>path</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>domain</parameter></methodparam> <methodparam choice="opt"><type>bool</type><parameter>secure</parameter></methodparam> </methodsynopsis> <para> <function>setrawcookie</function> は、 ブラウザに送信される際クッキーの値が自動的に URL エンコードされないことを除き、 <function>setcookie</function> と等価です。 </para> <para> <function>header</function>、<function>setcookie</function> および <link linkend="features.cookies">クッキーのセクション</link> も参照ください。 </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/phpdoc-ja/reference/network/functions/setcookie.xml?view=markup&rev=1.1 Index: phpdoc-ja/reference/network/functions/setcookie.xml +++ phpdoc-ja/reference/network/functions/setcookie.xml <?xml version="1.0" encoding="utf-8"?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.1 Maintainer: takagi Status: ready --> <refentry id="function.setcookie"> <refnamediv> <refname>setcookie</refname> <refpurpose>クッキーを送信する</refpurpose> </refnamediv> <refsect1> <title>説明</title> <methodsynopsis> <type>bool</type><methodname>setcookie</methodname> <methodparam><type>string</type><parameter>name</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>value</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>expire</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>path</parameter></methodparam> <methodparam choice="opt"><type>string</type><parameter>domain</parameter></methodparam> <methodparam choice="opt"><type>bool</type><parameter>secure</parameter></methodparam> </methodsynopsis> <para> <function>setcookie</function> は、その他のヘッダ情報と共に 送信するクッキーを定義します。 ほかのヘッダ情報と同様に、 クッキーは、スクリプトによる他のあらゆる出力よりも<emphasis>前に</emphasis> 送信される必要があります(これはHTTPプロトコルの制約です)。 <literal>&lt;html&gt;</literal> や <literal>&lt;head&gt;</literal> タグはもちろん 空白も含め、あらゆる出力よりも前にこの関数をコールするようにしなければなりません。 もしもこの関数をコールする前に何らかの出力がある場合には、 <function>setcookie</function> は失敗し &false; を返します。 <function>setcookie</function> が正常に実行されると、&true; を返します。 この関数はユーザーがクッキーを受け入れたかどうかを示すことはしません。 </para> <note> <para> PHP 4 では、この関数をコールする前でも出力できるように、 スクリプトの全ての出力をサーバ内にバッファリングさせることができます。 そのためには、<function>ob_start</function> や <function>ob_end_flush</function> を使用するか、あるいは &php.ini; の <literal>output_buffering</literal> 設定を使用します。 </para> </note> <para> <parameter>name</parameter> 以外の全ての引数はオプションです。 全ての引数に関して引数の指定をスキップするために空文字列 (<emphasis>&quot;&quot;</emphasis>) とすることが可能です。 <parameter>expire</parameter> および <parameter>secure</parameter> は数値なので、空文字列でスキップすることはできません。代わりにゼロ (<emphasis>0</emphasis>) を使用してください。 以下の表は <function>setcookie</function> の引数の説明です。 <function>setcookie</function> 関数の各引数が どのように作用するかを知るには <ulink url="&spec.cookies;">Netscape cookie specification</ulink> を、そして HTTP クッキーの動作についての詳細な情報は と<ulink url="&url.rfc;2965">RFC 2965</ulink> を参照ください。 </para> <para> <table> <title><function>setcookie</function> 引数の説明</title> <tgroup cols="3"> <thead> <row> <entry>引数</entry> <entry>説明</entry> <entry>例</entry> </row> </thead> <tbody> <row> <entry><parameter>name</parameter></entry> <entry> クッキーの名前 </entry> <entry> 'cookiename' が <varname>$_COOKIE['cookiename'] としてコールされます。</varname> </entry> </row> <row> <entry><parameter>value</parameter></entry> <entry> クッキーの値。この値はクライアントのコンピュータに保存されますので、 重要な情報は格納しないでください。 </entry> <entry> <parameter>name</parameter> が 'cookiename' だとすると、 その値は <varname>$_COOKIE['cookiename']</varname> で取得することができます。 </entry> </row> <row> <entry><parameter>expire</parameter></entry> <entry> クッキーの有効期限。これは Unix タイムスタンプなので Epoch(1970 年 1 月 1 日)からの経過秒数となります。 <function>time</function> または <function>mktime</function> 関数により 返された現在のUNIX標準時に、期限としたい必要な秒数を加算したものを 利用することができるでしょう。 </entry> <entry> <literal>time()+60*60*24*30</literal> はクッキーの有効期限を 30 日後にセットします。 もしも設定しない場合、クッキーはセッションの最後 (つまりブラウザを閉じるとき) が有効期限となります。 </entry> </row> <row> <entry><parameter>path</parameter></entry> <entry> サーバー上での、クッキーを有効としたいパス </entry> <entry> <literal>'/'</literal> をセットすると、クッキーは <parameter>domain</parameter> 配下の全てで有効となります。 <literal>'/foo/'</literal> をセットすると、クッキーは <literal>/foo/</literal> ディレクトリとそのサブディレクトリ配下 (例えば <literal>/foo/bar/</literal>) で有効となります。 デフォルト値は、クッキーがセットされたときのカレントディレクトリです。 </entry> </row> <row> <entry><parameter>domain</parameter></entry> <entry> クッキーが有効なドメイン </entry> <entry> exapmle.com の全てのサブドメインでクッキーを有効とするには <literal>'.example.com'</literal> をセットします。 <literal>.</literal> は必須ではありませんが、 多くのブラウザにおいて互換性があります。 <literal>www.example.com</literal> にセットすると、 クッキーは<literal>www</literal> サブドメインにおいてのみ有効となります。 末尾のマッチングについての詳細は <ulink url="&spec.cookies;">仕様</ulink> をご覧ください。 </entry> </row> <row> <entry><parameter>secure</parameter></entry> <entry> セキュアな HTTPS 接続の場合にのみクッキーが送信されるようにします。 &true; を設定すると、セキュアな接続が存在する場合にのみクッキーを 設定します。デフォルトは &false; です。 </entry> <entry> <literal>0</literal> または <literal>1</literal> </entry> </row> </tbody> </tgroup> </table> </para> <para> 一度クッキーが送信されると、次のページのロードからは <link linkend="reserved.variables.cookies">$_COOKIE</link> や <varname>$HTTP_COOKIE_VARS</varname> 配列によってクッキーにアクセスできます。 <varname>$_COOKIE</varname> のような <link linkend="language.variables.superglobals">autoglobals</link> は <ulink url="&url.php.release4.1.0;">4.1.0</ulink> 以降で有効となることに注意してください。 <varname>$HTTP_COOKIE_VARS</varname> は PHP 3 以降で使用できます。 クッキーの値は <link linkend="reserved.variables.request">$_REQUEST</link> 配列からもアクセスできます。 </para> <note> <para> PHPの <link linkend="ini.register-globals">register_globals</link> ディレクティブが <literal>on</literal> になっている場合、 クッキーは変数にも登録されています。 以下の例では、<varname>$TestCookie</varname> 変数が存在します。 <varname>$_COOKIE</varname> の使用が推奨されます。 </para> </note> <para> 陥りやすい失敗 <itemizedlist> <listitem> <simpara> クッキーは、クッキーを有効にするために次にページをロードするまで アクセスすることができません。クッキーが正常にセットされたか テストするために、クッキーの有効期限が切れる前に次のページを ロードしてクッキーをチェックしてください。 有効期限は <parameter>expire</parameter> 引数でセットされます。 クッキーの利用についてデバッグするのに良い方法は <literal>print_r($_COOKIE);</literal> をコールすることです。 </simpara> </listitem> <listitem> <simpara> クッキーは設定されたものと同じパラメータで削除する必要があります。 値が空文字列 ("") で、その他の全ての引数が前に setcookie をコールした時と同じである場合に、指定された名前のクッキーが リモートクライアント上から削除されます。 </simpara> </listitem> <listitem> <simpara> クッキーの値として &false; を設定すると、クッキーを削除しようとします。 そのため、boolean 値は使用できません。その代わりとして、 &false; ではなく <emphasis>0</emphasis>、そして &true; ではなく <emphasis>1</emphasis> を使用します。 </simpara> </listitem> <listitem> <simpara> クッキー名で配列を記述することにより、 クッキーの配列を設定することも可能ですが、複数のクッキー がユーザーのシステム上に保存されることになります。 <function>explode</function> を使用して ひとつのクッキー上に複数の名前と値をセットすることも 考慮してください。<function>serialize</function> の使用はセキュリティーホールになり得るため、 この目的のために使用することは推奨されません。 </simpara> </listitem> </itemizedlist> </para> <simpara> PHP 3 において同じスクリプトで <function>setcookie</function> を複数回コールした場合、逆の順番で実行されます。 他のクッキーを挿入する前にあるクッキーを削除しようとする場合、 削除する前に挿入を行う必要があります。PHP 4 では、 <function>setcookie</function> を複数回コールした場合でもコールした順番で実行されます。 </simpara> <para> 以下はクッキーを送信する例です。 <example> <title><function>setcookie</function> による送信のサンプル</title> <programlisting role="php"> <![CDATA[ <?php $value = 'something from somewhere'; setcookie("TestCookie", $value); setcookie("TestCookie", $value, time()+3600); /* 有効期限は一時間です */ setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".example.com", 1); ?> ]]> </programlisting> </example> </para> <para> クッキーの value の部分は、クッキーの送信を行う際に自動的に URL エンコードされ、またクッキーを受信した際は、自動的にデコード されてクッキー名と同じ名前の変数に格納されることに注意してください。 この挙動が気に入らない場合、もし PHP 5 を使用しているなら 代わりに <function>setrawcookie</function> を使ってください。 スクリプト内部で TestCookie の内容を見たい場合は、 以下のいずれかの例を使用します。 </para> <para> <informalexample> <programlisting role="php"> <![CDATA[ <?php // 個々のクッキーを表示します echo $_COOKIE["TestCookie"]; echo $HTTP_COOKIE_VARS["TestCookie"]; // デバッグ/テスト用には、全てのクッキーを見る方法があります。 print_r($_COOKIE); ?> ]]> </programlisting> </informalexample> </para> <para> クッキーを削除する場合には、ブラウザの削除機構を起動するために 必ず有効期限を過去に設定する必要があります。 次に、先ほど例で送信したクッキーを削除する例を示します。 </para> <para> <example> <title><function>setcookie</function> による削除の例</title> <programlisting role="php"> <![CDATA[ <?php // 有効期限を一時間前に設定します setcookie ("TestCookie", "", time() - 3600); setcookie ("TestCookie", "", time() - 3600, "/~rasmus/", ".example.com", 1); ?> ]]> </programlisting> </example> </para> <para> クッキー名で配列を記述することにより、クッキーの配列を設定することも可能です。 これにより配列要素と同数のクッキーを設定されますが、 クッキーがスクリプトに受信された際に、 値はクッキー名を有する配列に置きかえられます。 </para> <para> <example> <title><function>setcookie</function> と配列</title> <programlisting role="php"> <![CDATA[ <?php // クッキーを設定します setcookie("cookie[three]", "cookiethree"); setcookie("cookie[two]", "cookietwo"); setcookie("cookie[one]", "cookieone"); // ページを再読み込みした後に、表示します if (isset($_COOKIE['cookie'])) { foreach ($_COOKIE['cookie'] as $name => $value) { echo "$name : $value <br />\n"; } } ?> ]]> </programlisting> <para> この結果は、次のようになります。 </para> <screen> <![CDATA[ three : cookiethree two : cookietwo one : cookieone ]]> </screen> </example> </para> <note> <para> <ulink url="&url.rfc;2109">RFC 2109</ulink> および <ulink url="&url.rfc;2965">RFC 2695</ulink> も参考になるでしょう。 </para> <para> <parameter>expire</parameter> パラメータには、<literal>Wdy, DD-Mon-YYYY HH:MM:SS GMT</literal> といった形式ではなく Unix タイムスタンプを渡していることにお気づきでしょうか。 これは、PHP の内部で自動的に変換を行っているからです。 </para> <para> <parameter>expire</parameter> は、クライアントの時刻と比較されます。 サーバの時刻との比較ではありません。 </para> </note> <note> <simpara> サービスパック 1 を適用した Microsoft Internet Explorer 4 は、 パスに関するパラメータを設定したクッキーを正確に処理することができません。 </simpara> <simpara> Netscape Communicator 4.05 および Microsoft Internet Explorer 3.x は、path と time が設定されていない場合、 クッキーを正確に処理することができないようです。 </simpara> </note> <para> <function>header</function>、<function>setrawcookie</function> および<link linkend="features.cookies">クッキーのセクション</link> も参照ください。 </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/phpdoc-ja/reference/network/functions/headers-sent.xml?view=markup&rev=1.1 Index: phpdoc-ja/reference/network/functions/headers-sent.xml +++ phpdoc-ja/reference/network/functions/headers-sent.xml <?xml version="1.0" encoding="utf-8"?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.1 Maintainer: takagi Status: ready --> <refentry id="function.headers-sent"> <refnamediv> <refname>headers_sent</refname> <refpurpose>ヘッダが既に送信されているかどうかを調べる</refpurpose> </refnamediv> <refsect1> <title>説明</title> <methodsynopsis> <type>bool</type><methodname>headers_sent</methodname> <methodparam choice="opt"><type>string</type><parameter role="reference">file</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter role="reference">line</parameter></methodparam> </methodsynopsis> <simpara> <function>headers_sent</function> は、HTTP ヘッダが既に送信されている場合に &true; 、そうでない場合に &false; を返します。 また、オプション引数の <parameter>file</parameter> と <parameter>line</parameter> がセットされている場合、 PHP のソースファイル名と出力が開始された行番号が、それぞれ <parameter>file</parameter> と <parameter>line</parameter> に格納されます。 </simpara> <simpara> ヘッダブロックがいったん送信されてしまった後で <function>header</function> 関数を使って新たなヘッダ行を送信することはできません。 この関数を使うには、少なくとも HTTP ヘッダ関連のエラーを予防する必要があります。 あるいは、<link linkend="ref.outcontrol">出力バッファリング</link>を 使う方法もあります。 </simpara> <note> <simpara> オプションのパラメータ <parameter>file</parameter> と <parameter>line</parameter> が PHP 4.3.0 で追加されました。 </simpara> </note> <para> <example> <title><function>headers_sent</function> 関数の使用例</title> <programlisting role="php"> <![CDATA[ <?php // ヘッダがまだ何も送信されていない場合に、送信します if (!headers_sent()) { header('Location: http://www.example.com/'); exit; } // オプションのfileとlineパラメータの使用例(PHP4.3.0以降) // $filename と $linenum が後で使用されていることに注目。 // これらの変数に事前に値を与えたりしてはいけません。 if (!headers_sent($filename, $linenum)) { header('Location: http://www.example.com/'); exit; // おそらく、ここでエラー処理を行うでしょう。 } else { echo "$filename の $linenum 行目でヘッダがすでに送信されています。\n" . "リダイレクトできません。代わりにこの <a " . "href=\"http://www.example.com\">リンク</a> をクリックしてください。\n"; exit; } ?> ]]> </programlisting> </example> </para> <para> これに関連するより詳細な議論は <function>ob_start</function>、 <function>trigger_error</function>、 <function>header</function> を参照ください。 </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/phpdoc-ja/reference/network/functions/headers-list.xml?view=markup&rev=1.1 Index: phpdoc-ja/reference/network/functions/headers-list.xml +++ phpdoc-ja/reference/network/functions/headers-list.xml <?xml version="1.0" encoding="utf-8"?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.1 Maintainer: takagi Status: ready --> <refentry id="function.headers-list"> <refnamediv> <refname>headers_list</refname> <refpurpose>送信した (もしくは送信される予定の) レスポンスヘッダの一覧を返す</refpurpose> </refnamediv> <refsect1> <title>説明</title> <methodsynopsis> <type>array</type><methodname>headers_list</methodname> <void/> </methodsynopsis> <simpara> <function>headers_list</function> はブラウザもしくはクライアントに送信されるヘッダの数値配列を返します。 これらのヘッダが送信されたかどうかを判断するためには <function>headers_sent</function> を使用します。 </simpara> <para> <example> <title><function>headers_list</function> の使用例</title> <programlisting role="php"> <![CDATA[ <?php /* setcookie() でレスポンスヘッダをそれ自身に追加します */ setcookie('foo', 'bar'); /* 独自のレスポンスヘッダを定義します。 これはほとんどのクライアントで無視される */ header("X-Sample-Test: foo"); /* レスポンスがプレーンテキストだと宣言します */ header('Content-type: text/plain'); /* 送信しようとしているヘッダは? */ var_dump(headers_list()); ?> ]]> </programlisting> <para> この出力は次の通りです。 </para> <screen> <![CDATA[ array(4) { [0]=> string(23) "X-Powered-By: PHP/5.1.3" [1]=> string(19) "Set-Cookie: foo=bar" [2]=> string(18) "X-Sample-Test: foo" [3]=> string(24) "Content-type: text/plain" } ]]> </screen> </example> </para> <simpara> <function>headers_sent</function>、 <function>header</function> および <function>setcookie</function> も参照ください。 </simpara> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/viewvc.cgi/phpdoc-ja/reference/network/functions/header.xml?view=markup&rev=1.1 Index: phpdoc-ja/reference/network/functions/header.xml +++ phpdoc-ja/reference/network/functions/header.xml <?xml version="1.0" encoding="utf-8"?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.1 Maintainer: takagi Status: ready --> <refentry id="function.header"> <refnamediv> <refname>header</refname> <refpurpose>生の HTTP ヘッダを送信する</refpurpose> </refnamediv> <refsect1> <title>説明</title> <methodsynopsis> <type>void</type><methodname>header</methodname> <methodparam><type>string</type><parameter>string</parameter></methodparam> <methodparam choice="opt"><type>bool</type><parameter>replace</parameter></methodparam> <methodparam choice="opt"><type>int</type><parameter>http_response_code</parameter></methodparam> </methodsynopsis> <para> <function>header</function> は、生の <acronym>HTTP</acronym> ヘッダを送信するために使用されます。 <acronym>HTTP</acronym> ヘッダについての詳細な情報は <ulink url="&url.rfc;2616">HTTP/1.1 仕様</ulink> を参照ください。 </para> <note> <para> PHP 4.4.2 および PHP 5.1.2 以降、この関数は一度に複数のヘッダを 送信できないようになりました。これは、 ヘッダインジェクション攻撃への対策です。 </para> </note> <para> オプションのパラメータ <parameter>replace</parameter> は、ヘッダが 前に送信された類似のヘッダを置換するか、または、同じ形式の二番目の ヘッダを追加するかどうかを指定します。デフォルトでは、この関数は 置換を行ないますが、二番目の引数に &false; を指定すると、同じ型の 複数のヘッダを強制的に生成します。例えば、 </para> <para> <informalexample> <programlisting role="php"> <![CDATA[ <?php header('WWW-Authenticate: Negotiate'); header('WWW-Authenticate: NTLM', false); ?> ]]> </programlisting> </informalexample> </para> <para> 第二オプション引数 <parameter>http_response_code</parameter> は HTTP レスポンスコードを強制的に指定の値にします (このパラメータは PHP 4.3.0 以降で有効です)。 </para> <para> 特殊な header コールが 2 種類あります。最初のものは、 文字列 "<literal>HTTP/</literal>" から始まる全てのヘッダ (大文字・小文字は区別されません) です。 このヘッダは、送信する HTTP ステータスコードを示すために使用されます。 例えば、存在しないファイルへのリクエストを処理するためにある PHP スクリプトを使用するよう (<literal>ErrorDocument</literal> ディレクティブにより) Apache を設定する場合、 そのスクリプトが正しいステータスコードを返すようにする必要があります。 </para> <para> <informalexample> <programlisting role="php"> <![CDATA[ <?php header("HTTP/1.0 404 Not Found"); ?> ]]> </programlisting> </informalexample> </para> <note> <para> 実際に <function>header</function> が最初にコールされたか どうかにかかわらず、HTTP ステータスヘッダ行は クライアントに対し常に最初に送信されます。 HTTP ヘッダが既に送信されていない限り、 <function>header</function> をコールすることでステータスは 常に上書きされます。 </para> </note> <para> 2 番目の特別なヘッダは、"Location:" ヘッダです。このヘッダがブラウザに返されるだけではなく、 ブラウザに <literal>REDIRECT</literal> (302) ステータスコードを返します (<literal>3xx</literal> ステータスコードが既に送信されていない場合にのみ)。 </para> <para> <informalexample> <programlisting role="php"> <![CDATA[ <?php header("Location: http://www.example.com/"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> ]]> </programlisting> </informalexample> </para> <note> <para> HTTP/1.1 では、スキーム、ホスト名、絶対パスを含む絶対 <acronym>URI</acronym> が <ulink url="&spec.http1.1;-sec14.html#sec14.30">Location:</ulink> の引数として必要ですが、相対 URI を受け付けるクライアントもあります。 通常は、相対 URI から絶対 URI を作成するためには $_SERVER['HTTP_HOST']、$_SERVER['PHP_SELF'] および <function>dirname</function> を使用できます。 <informalexample> <programlisting role="php"> <![CDATA[ <?php /* カレントディレクトリの別のページにリダイレクトします */ $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'mypage.php'; header("Location: http://$host$uri/$extra"); exit; ?> ]]> </programlisting> </informalexample> </para> </note> <note> <para> <link linkend="ini.session.use-trans-sid">session.use_trans_sid</link> が有効であったとしても、セッション ID が Location ヘッダとともに 渡されることはありません。<constant>SID</constant> 定数を使用して 手動で渡す必要があります。 </para> </note> <para> PHP スクリプトはしばしば動的に HTML を生成するため、クライアント ブラウザやサーバおよびクライアントブラウザの間でプロキシがキャッシュを 行ったりするべきではありません。多くのプロキシとクライアントでは、 以下のコードにより強制的にキャッシュを無効にできます。 </para> <para> <informalexample> <programlisting role="php"> <![CDATA[ <?php header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // 過去の日付 ?> ]]> </programlisting> </informalexample> </para> <note> <para> 上記のヘッダを全て出力しなかったとしてもページのキャッシュが 行われない場合があることに気付くかもしれません。デフォルトの ブラウザのキャッシュの動作をユーザが変更できる手段はいくつもあります。 上記のヘッダを送信することにより、スクリプトの出力がキャッシュされる 可能性がある設定を上書きするべきです。 </para> <para> さらに、<function>session_cache_limiter</function> および 設定 <literal>session.cache_limiter</literal> を用いると、 セッションが使用された際にキャッシュ関係の正しいヘッダを 自動的に生成させることもできます。 </para> </note> <para> 覚えておいて頂きたいのは、<function>header</function> 関数は、 通常の HTML タグまたは PHP からの出力にかかわらず、すべての実際の 出力の前にコールする必要があることです。 頻出するエラーとして、<function>include</function> または <function>require</function> 関数、他のファイルをアクセスする関数に 空白または空行があり、<function>header</function> の前に出力が 行われてしまうというものがあります。同じ問題は、単一の PHP/HTML ファイルを使用している場合でも存在します。 </para> <para> <informalexample> <programlisting role="php"> <![CDATA[ <html> <?php /* これはエラーとなります。この上に出力があることに注目してください。 * それはheader()のコールより前であるということになります */ header('Location: http://www.example.com/'); ?> ]]> </programlisting> </informalexample> </para> <note> <para> PHP 4 では、出力のバッファリングを使用してこの問題を回避することができます。 この場合、ブラウザへの出力が送信するまでサーバに 全てバッファリングされるオーバーヘッドがあります。出力バッファリングは、 <function>ob_start</function> と <function>ob_end_flush</function> をスクリプトでコールするか &php.ini; またはサーバ設定ファイルの設定ディレクティブ <literal>output_buffering</literal> を設定することにより 行うことが可能です。 </para> </note> <para> PDF ファイルを生成するといったように送信するデータを保存するかどうか ユーザにプロンプトを表示したい場合、推奨されるファイル名を指定して ブラウザに保存ダイアログを表示させる<ulink url="&url.rfc;2183">Content-Disposition</ulink> ヘッダを使用可能です。 </para> <para> <informalexample> <programlisting role="php"> <![CDATA[ <?php // PDFを出力します header('Content-type: application/pdf'); // downloaded.pdf という名前で保存させます header('Content-Disposition: attachment; filename="downloaded.pdf"'); // もとの PDF ソースは original.pdf です readfile('original.pdf'); ?> ]]> </programlisting> </informalexample> </para> <note> <para> Microsoft Internet Explorer 4.01 にはバグがあり、 この方法が動作しません。これを解決する方法はありません。 同様に Microsoft Internet Explorer 5.5 にもこれを妨げるバグがあります。 こちらは、サービスパック 2 以降にアップグレードすることで対応できます。 </para> </note> <note> <simpara> <link linkend="ini.safe-mode">セーフモード</link>が有効な場合は、 <literal>WWW-Authenticate</literal> ヘッダ (HTTP 認証に使用する) を設定した際に、スクリプトの uid が <literal>realm</literal> 部に追加されます。 </simpara> </note> <para> <function>headers_sent</function>、 <function>setcookie</function> および <link linkend="features.http-auth">HTTP 認証</link> の節も参照ください。 </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t indent-tabs-mode:nil sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.doc.ja (#1586) next »