user364622
user364622

Reputation: 366

PHP - getting content of the POST request

I have problem with getting the content. I don't know the names of the post variables so I can't do this using

$variable = $_POST['name']; 

because I don't know the "name". I want to catch all of the variables sent by POST method. How can I get keys of the $_POST[] array and the corresponding values?

Upvotes: 0

Views: 10777

Answers (7)

Void
Void

Reputation: 1502

To get the keys:

array_keys($_POST);

Upvotes: 0

Jeg Bagus
Jeg Bagus

Reputation: 1

basically post request will be mapped to array. for debuging you can call

var_dump($_POST);

this code will list all array within post array.

Upvotes: 0

Eugene
Eugene

Reputation: 4389

Besides print_r($_POST); you could also use var_dump($_POST);, but most logical solution as mentioned earlier is foreach loop.

Upvotes: 0

wag2639
wag2639

Reputation: 2583

for some quick debugging, you can also use

print_r ($_POST)

Upvotes: 1

Adam Pope
Adam Pope

Reputation: 3274

Just use a for each loop

foreach($_POST as $key => $value){
   echo "$key = $value";
}

Upvotes: 0

Aaron Butacov
Aaron Butacov

Reputation: 34347

$_POST is just a big array:

while(list($keys,$vars) = each($_POST)){ // do something. }

Upvotes: 2

Matthew Flaschen
Matthew Flaschen

Reputation: 284816

Standard for-each:

foreach ($_POST as $key => $value)
{
  // ... Do what you want with $key and $value
}

Upvotes: 7

Related Questions