Reading in all POST and GET variables
September 12th, 2006 Posted in PHPThis simple one liner will read in all of the variables sent via POST and GET and turn them into relevant variables within this new page, so $_GET[variable] becomes $variable automatically.
@extract($_POST);
@extract($_GET);
If this doesnt work, and some server setups stop your from doing the above, then you can use a variable variable (yes thats right, you did read it correctly) with the following code
foreach ($_POST as $key => $value)
$$key = $value;
This basically says that if $_POST['myvariable'] exists then it will create $myvariable. This is also a very easy way of filtering all input because you can simply add an extra line in the for loop like the below…
foreach ($_POST as $key => $value){
$temp = stripslashes($value);
$$key = $temp;
}
One Response to “Reading in all POST and GET variables”
By Alex on Apr 25, 2007
Thank You