Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read post request without knowing variables passed?

Tags:

post

php

I'm trying to read a post request sent from a client using PHP whether they pass variables or not. What I want is to read the post data. I have tried using, the following without any luck:

echo file_get_contents('php://input');

I have tried sending the post request to http://posttestserver.com/ and the HTTP Post returns 200 and shows the post data sent to it.

How do I go about this using php?

like image 989
h4kl0rd Avatar asked Jul 26 '15 12:07

h4kl0rd


1 Answers

You can read the post data from the $_POST variable. If you want to know which keys the array holds, use array_keys():

$postKeys = array_keys($_POST);

Alternatively, you could use foreach to scan the array:

foreach ($_POST as $key => $value) {
    echo "Key: $key; Value: $value\n";
}
like image 68
Aviram Avatar answered Dec 07 '22 10:12

Aviram