Monday, 1 November 2010

Get All Posted Variables and Set As PHP Strings

So, A quick starter for today - we use this practically everyday. First off, if you are using forms in html code, give the inputs meaningful names. To capture the variables in the target page, use the PHP below :
<\?PHP
// get single, named posted variables from previous web page
if (isset($_REQUEST['username'])) {
$username = $_REQUEST['username'];
// you may prefer to have addslashes() in here...
} else {
$username = "default";
}
?>

Each input variable will now be a meaningful PHP variable of the same name.
More to follow - with escape characters and arrays too...
But, how about this for simplcity:
//
// parse the $_REQUEST vars
foreach($_REQUEST as $varname => $input) {
${$varname} = $input;
}
Now ANY and ALL variables posted will be set up for you to use as you wish!

No comments:

Post a Comment