Getting all keys for a card, for example $ _POST

For example, let's say I send some data to a php file, but I do not know what the names of these values ​​are. Where would I usually do $_POST["username"]or something like that. How do I get a list of all key / value pairs inside$_POST

+5
source share
2 answers

array_keys($_POST) will give you array keys.

You can also do this to get values ​​with key names:

foreach ($_POST as $key => $value) 
{
    //do stuff; 
}

However!!! Why don't you know which keys are in this post? You do not want hackers to put random things in a message, send it to you and process it. Nothing prevents them from posting 1000 entries.

+7
source

array_keys, $_POST:

array_keys($_POST)

:

foreach (array_keys($_POST) as $key)
{
    print $_POST[$key];
}
+7

All Articles