I submit as POST to a php page the following:
{a:1}
This is the body of the request (a POST request).
In php, what do I have to do to extract that value?
var_dump($_POST);
is not the solution, not working.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To access the entity body of a POST or PUT request (or any other HTTP method):
Also, the
STDINconstant is an already-open stream tophp://input, so you can alternatively do:From the PHP manual entry on I/O streamsdocs:
Specifically you’ll want to note that the
php://inputstream, regardless of how you access it in a web SAPI, is not seekable. This means that it can only be read once. If you’re working in an environment where large HTTP entity bodies are routinely uploaded you may wish to maintain the input in its stream form (rather than buffering it like the first example above).To maintain the stream resource something like this can be helpful:
php://tempallows you to manage memory consumption because it will transparently switch to filesystem storage after a certain amount of data is stored (2M by default). This size can be manipulated in the php.ini file or by appending/maxmemory:NN, whereNNis the maximum amount of data to keep in memory before using a temporary file, in bytes.Of course, unless you have a really good reason for seeking on the input stream, you shouldn’t need this functionality in a web application. Reading the HTTP request entity body once is usually enough — don’t keep clients waiting all day while your app figures out what to do.
Note that php://input is not available for requests specifying a
Content-Type: multipart/form-dataheader (enctype="multipart/form-data"in HTML forms). This results from PHP already having parsed the form data into the$_POSTsuperglobal.