note 87583 deleted from reserved.variables.post by danbrown
| From: | danbrown@php.net | Date: | Thu, 11 Dec 2008 15:28:26 +0000 |
| Subject: | note 87583 deleted from reserved.variables.post by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148032@lists.php.net to get a copy of this message | ||
Note Submitter: skchandon at skchandon dot com
----
A great way to get all the post/get variables. Beware: may have security issues:
<?php
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//the following function will accept the get or post
//collection and create variables out of the submitted data
function createVars(&$arr_post_var)
{
if ( $arr_post_var )
{
foreach ( $arr_post_var as $strKey=>$strItem )
{
$strItem = cleanItem($strItem);
eval("global \$$strKey;\$$strKey=\"$strItem\";");
}
}
}
//ENd function createVars(&$arr_post_var)
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
?>
so now all you do
<?php
if ( $_GET )
{
createVars($_GET);
}
if ( $_POST )
{
createVars($_POST);
}
?>
The idea behind this approach is this: if you are passing a querystring from ajax then
whatever variables you have in your querystring, the function above will create equivalent php
variables and assign the proper value. So essentially
if your querystring has something like the following:
"firstname=shah&phone=555555"
then in your php you will have
$firstname="shah";
$phone="555555";
But please note this might pose a security threat.