Is there a way or piece of code that looks for POST and GET data and turns them into normal variables?
I mean it to make:
$_POST["hello"] = "Wow."
into
$hello = "Wow."
But also be able to do it automatically and with many POSTS and GETS, so like this:
$_POST["name"]="John";
$_GET["email"]="john@john.com";
$_POST["sex"]="male";
into
$name="John";
$email="john@john.com";
$sex="male";
I know the second example is impossible (you can’t get GET and POST data at the same time (or so I know), but the idea is that whether the page gets a GET or a POST variable it should turn it into variables automatically.
So is there a function or something that can help me?
You can use extract():
extract($_REQUEST);($_REQUESTcombines$_POSTand$_GET)But I would consider it as bad practice, because it adds some black magic to your code which can lead to unpredictable situations. Also it’s easily exploitable:
Consider that you have a variable:
$secret = 100;which nobody should change.Now comes a kinky user and injects following POST variable in a form submit:
$_POST['secret'] = 200;There you have the exploitation!