Skip to content

Commit 612be8c

Browse files
committed
Improve $_POST/$_GET definition
php/doc-en@f56de7e
1 parent 0165632 commit 612be8c

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

language/predefined/variables/get.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: cdaea0421544885f02ff3d36bd203dc01b78299e Maintainer: satoruyoshida Status: ready -->
3+
<!-- EN-Revision: f56de7ebe7a1a85ce9e44a2bf6b77b07adfe3ae4 Maintainer: satoruyoshida Status: ready -->
44
<!-- CREDITS: mumumu -->
55

66
<refentry role="variable" xml:id="reserved.variables.get" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
77
<refnamediv>
88
<refname>$_GET</refname>
9-
<refpurpose>HTTP GET 変数</refpurpose>
9+
<refpurpose>クエリストリング変数</refpurpose>
1010
</refnamediv>
1111

1212
<refsect1 role="description">
1313
&reftitle.description;
1414
<para>
1515
URL パラメータ (a.k.a クエリストリング) で現在のスクリプトに渡された変数の連想配列です。
16-
この配列の値は、GETリクエストだけでなく、クエリストリングが含まれた全てのリクエストで収集されることに注意して下さい。
16+
この配列の値は、HTTP リクエストメソッドに関係なく、クエリストリングが含まれた全てのリクエストで収集されることに注意して下さい。
1717
</para>
1818

1919
</refsect1>
@@ -31,7 +31,7 @@ echo 'Hello ' . htmlspecialchars($_GET["name"]) . '!';
3131
]]>
3232
</programlisting>
3333
<simpara>
34-
ユーザーが http://example.com/?name=Hannes と入力したとします。
34+
ユーザーが <literal>http://example.com/?name=Hannes</literal> と入力したとします。
3535
</simpara>
3636
&example.outputs.similar;
3737
<screen>
@@ -48,7 +48,7 @@ Hello Hannes!
4848
&note.is-superglobal;
4949
<note>
5050
<para>
51-
GET 変数は <function>urldecode</function> 関数を介して渡されます
51+
<varname>$_GET</varname> の値は <function>urldecode</function> 関数を介して自動的に渡されます
5252
</para>
5353
</note>
5454
</refsect1>

language/predefined/variables/post.xml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: cdaea0421544885f02ff3d36bd203dc01b78299e Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: f56de7ebe7a1a85ce9e44a2bf6b77b07adfe3ae4 Maintainer: takagi Status: ready -->
44
<!-- Credits: mumumu -->
55

66
<refentry role="variable" xml:id="reserved.variables.post" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
77
<refnamediv>
88
<refname>$_POST</refname>
9-
<refpurpose>HTTP POST 変数</refpurpose>
9+
<refpurpose>HTTP POST リクエストから得られるフォームデータ</refpurpose>
1010
</refnamediv>
1111

1212
<refsect1 role="description">
@@ -32,7 +32,8 @@ echo 'Hello ' . htmlspecialchars($_POST["name"]) . '!';
3232
]]>
3333
</programlisting>
3434
<simpara>
35-
ユーザーが name=Hannes と POST したとします。
35+
ユーザーがリクエストボディに <literal>name=Hannes</literal>
36+
を付けて POST リクエストを送信したとします。
3637
</simpara>
3738
&example.outputs.similar;
3839
<screen>
@@ -47,6 +48,20 @@ Hello Hannes!
4748
<refsect1 role="notes">
4849
&reftitle.notes;
4950
&note.is-superglobal;
51+
<note>
52+
<simpara>
53+
その他の content type
54+
(例: <literal>application/json</literal> や
55+
<literal>application/xml</literal>)
56+
を指定して送信された POST データを読み取るには、
57+
<link linkend="wrappers.php.input"><filename>php://input</filename></link>
58+
を使わなければいけません。
59+
<literal>application/x-www-form-urlencoded</literal> と
60+
<literal>multipart/form-data</literal> を指定した場合にだけ動作する
61+
<varname>$_POST</varname> とは異なり、
62+
<filename>php://input</filename> はリクエストボディの生データに直接アクセスします。
63+
</simpara>
64+
</note>
5065
</refsect1>
5166

5267
<refsect1 role="seealso">

language/wrappers/php.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
3-
<!-- EN-Revision: 0592e6316d3869b49637df29c471097e7bf78592 Maintainer: takagi Status: ready -->
3+
<!-- EN-Revision: f56de7ebe7a1a85ce9e44a2bf6b77b07adfe3ae4 Maintainer: takagi Status: ready -->
44
<!-- CREDITS: hirokawa,mumumu -->
55

66
<refentry xml:id="wrappers.php" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" annotations="verify_info:false" role="stream_wrapper">
@@ -363,6 +363,28 @@ file_put_contents("php://filter/write=string.rot13/resource=example.txt","Hello
363363
<?php
364364
file_put_contents('php://memory', 'PHP');
365365
echo file_get_contents('php://memory'); // 何も表示されません
366+
]]>
367+
</programlisting>
368+
</example>
369+
<example>
370+
<title>リクエストボディから、JSON データを読み取るために php://input を使う</title>
371+
<para>
372+
この例は、<filename>php://input</filename> を使って POST, PUT,
373+
PATCH リクエスト経由で生の JSON データを読み取る方法を示します。
374+
</para>
375+
<programlisting role="php">
376+
<![CDATA[
377+
<?php
378+
$input = file_get_contents("php://input");
379+
$json_array = json_decode(
380+
json: $input,
381+
associative: true,
382+
flags: JSON_THROW_ON_ERROR
383+
);
384+
385+
echo "Received JSON data: ";
386+
print_r($json_array);
387+
?>
366388
]]>
367389
</programlisting>
368390
</example>

0 commit comments

Comments
 (0)