For example, say I post some data to a php file, but I don't know what the names of those values are. Where I would normally perform $_POST["username"]
or something similar. How would I go about getting a list of all the key/value pairs within $_POST
array_keys($_POST)
will give you the array keys.
You can also do this to get values with key names:
foreach ($_POST as $key => $value)
{
//do stuff;
}
However!!! Why wouldn't you know what keys are in the post? You don't want hackers putting random stuff into a post, sending it to you, and processing away. There is nothing preventing them from putting in 1000s of entries.
Use array_keys
to obtain all keys in $_POST
super global array:
array_keys($_POST)
Simple example:
foreach (array_keys($_POST) as $key)
{
print $_POST[$key];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With