Home >Backend Development >PHP Problem >What should I do if php cannot capture data?

What should I do if php cannot capture data?

藏色散人
藏色散人Original
2022-10-26 09:55:521785browse

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',},".

What should I do if php cannot capture data?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn