Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is "php://input"? It mainly seen in webservice

Tags:

php

What is the relevance of php://input in the following snippet, and what is it used for?

$json_string = GPTake(array('json_string'));
$handle = fopen('php://input', 'r');
$jsonInput = fgets($handle);

$test = json_decode($jsonInput);
like image 901
User1988 Avatar asked Dec 28 '11 13:12

User1988


People also ask

What is the use of input in PHP?

php://input php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives.

How to display the submitted FORM data in PHP?

Try it Yourself ». When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method. To display the submitted data you could simply echo all the variables.

What is the difference between $HTTP_Raw_post_data and $input?

php://input. php://input is a read-only stream that allows you to read raw data from the request body. In the case of POST requests, it is preferable to use php://input instead of $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives.

How is form data sent to a PHP file?

When the user fills out the form above and clicks the submit button, the form data is sent for processing to a PHP file named "welcome.php". The form data is sent with the HTTP POST method.


2 Answers

It gives you direct access to the input stream, as opposed to accessing the data after PHP has already applied the $_GET/$_POST super globals. Also, according to the manual, it is both less intensive and allows you to grab information before any php.ini directives have been applied.

For more information, read the PHP Manual on php://input

like image 54
Brad Christie Avatar answered Oct 02 '22 16:10

Brad Christie


php:// is a scheme wrapper around various input/output streams that PHP supports. You can read up for here: http://www.php.net/manual/en/wrappers.php.php.

Specifically, php://input allows you to read the input stream directly.

like image 36
Matthew Abbott Avatar answered Oct 02 '22 16:10

Matthew Abbott