Reputation: 857
Is there a way to get a reference to the global arrays that contain HTTP request data like get, post, cookie, etc. ? For example:
$varName = getRequestReference()['varName'];
where getRequestReference() would return &$_GET, &$_POST...depending on the type of request that the user used to submit data in the script.
Upvotes: 0
Views: 84
Reputation: 37905
You can use $_REQUEST
to either grab the $_POST
, $_GET
or $_COOKIE
values
See the documentation for more details.
You could also create a custom function that either grabs $_POST
or $_GET
, depending which has the requested key:
function getRequest($key)
{
if(!empty($_GET[$key]))
{
return $_GET[$name];
}
if(!empty($_POST[$key]))
{
return $_POST[$name];
}
return null;
}
$varValue = getRequest('varName');
This function will return the updated values (when you modify one of these global variables at run-time)
Upvotes: 0