file_get_contents('php://input'); 解释
时间: 2024-02-04 07:54:12 浏览: 32
file_get_contents('php://input') is a PHP function that reads the raw HTTP request body from the input stream. It returns the content as a string. This is commonly used in PHP scripts that handle HTTP requests to retrieve data that has been sent from a client, such as form data or JSON payloads. The 'php://input' stream is a read-only stream that allows access to the raw input data, regardless of the request method used (e.g. GET, POST, PUT, DELETE, etc.).
相关问题
file_ get_ contents 参数:' php://input "是不是后门
不是的,"php://input" 是 PHP 中一个特殊的输入流,它用于获取 HTTP 请求的原始数据,是 PHP 内置的一个标准输入流,没有任何后门的功能。它在处理 HTTP POST 请求时非常常用,可以用于获取 POST 请求中的表单数据、JSON 数据等。如果在使用 "file_get_contents('php://input')" 时,传入了非法的参数或者从未经过处理的数据,可能会导致安全问题。但这并不意味着 "php://input" 本身是一个后门。
我是用php中的file_get_contents("php://input")取不到值
`file_get_contents("php://input")` 可以用于获取 HTTP 请求的原始数据,包括 POST 请求的数据。但是需要注意的是,使用该函数时需要确保请求头中设置了 Content-Type,否则无法获取到数据。
例如,如果请求头中设置了 Content-Type 为 application/json,则可以通过以下方式获取 POST 请求的 JSON 数据:
```
$json_data = file_get_contents("php://input");
$data = json_decode($json_data, true);
```
如果请求头中设置了 Content-Type 为 application/x-www-form-urlencoded,则可以通过以下方式获取 POST 请求的表单数据:
```
$form_data = file_get_contents("php://input");
parse_str($form_data, $data);
```
需要注意的是,`file_get_contents("php://input")` 只能获取 POST 请求的数据,如果是 GET 请求则无法获取到数据。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)