Solution to the problem that php cannot capture data: 1. Use "$parm=file_get_contents("php://input");" on the server; 2. The front-end sends a request header with code such as "method: 'POST',header:{'Content-Type':'application/x-www-form-urlencoded',},".
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.
What should I do if php cannot capture the data?
Using $_POST['email'] fails to obtain the request data.
$parm=file_get_contents("php://input");//可以获取到请求头Content-Type: application/json var_dump($parm); var_dump($_POST['email']);//请求头Content-Type: application/x-www-form-urlencoded var_dump($_POST['password']);//请求头Content-Type: application/x-www-form-urlencoded
Official website$_POST description
When the Content-Type of the HTTP POST request is application/x-www-form-urlencoded or multipart/form-data, the variable will be in the form of an associative array Pass in the current script
Solution 1: Use on the server
$parm=file_get_contents("php://input");//可以获取到请求头Content-Type: application/json
Solution 2: Send request headers to the front end
method:'POST', header:{ 'Content-Type':'application/x-www-form-urlencoded', },
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of What should I do if php cannot capture data?. For more information, please follow other related articles on the PHP Chinese website!