diff --git a/language/predefined/variables/get.xml b/language/predefined/variables/get.xml index 8d0663992d35..8b3f0160a3c8 100644 --- a/language/predefined/variables/get.xml +++ b/language/predefined/variables/get.xml @@ -4,15 +4,16 @@ $_GET - HTTP GET variables + Query string variables &reftitle.description; - An associative array of variables passed to the current script - via the URL parameters (aka. query string). Note that the array is not only - populated for GET requests, but rather for all requests with a query string. + An associative array of variables passed to the current script via the URL + parameters (also known as the query string). Note that this array is + populated whenever a query string is present, regardless of the HTTP request + method. @@ -29,7 +30,7 @@ echo 'Hello ' . htmlspecialchars($_GET["name"]) . '!'; ]]> - Assuming the user entered http://example.com/?name=Hannes + Assuming the user entered http://example.com/?name=Hannes. &example.outputs.similar; @@ -46,7 +47,7 @@ Hello Hannes! ¬e.is-superglobal; - The GET variables are passed through urldecode. + The values in $_GET are automatically passed through urldecode. diff --git a/language/predefined/variables/post.xml b/language/predefined/variables/post.xml index 3ffe08affece..b74304ee8d30 100644 --- a/language/predefined/variables/post.xml +++ b/language/predefined/variables/post.xml @@ -4,7 +4,7 @@ $_POST - HTTP POST variables + Form data from HTTP POST requests @@ -29,7 +29,8 @@ echo 'Hello ' . htmlspecialchars($_POST["name"]) . '!'; ]]> - Assuming the user POSTed name=Hannes + Assuming the user sent a POST request with name=Hannes + in the body. &example.outputs.similar; @@ -44,6 +45,17 @@ Hello Hannes! &reftitle.notes; ¬e.is-superglobal; + + + To read POST data sent with other content types (e.g. + application/json or application/xml) + php://input + must be used. Unlike $_POST, which only works with + application/x-www-form-urlencoded and + multipart/form-data, php://input + provides direct access to the raw data from the body of the request. + + diff --git a/language/wrappers/php.xml b/language/wrappers/php.xml index 7c1295122d65..3a03bb46f985 100644 --- a/language/wrappers/php.xml +++ b/language/wrappers/php.xml @@ -368,6 +368,28 @@ file_put_contents("php://filter/write=string.rot13/resource=example.txt","Hello + + + + php://input to read JSON data from the request body + + This example demonstrates how to read raw JSON data from POST, PUT and + PATCH requests using php://input. + + + ]]>