Jump to content

How do I use $_REQUEST to get a list of variables?


php_joe

Recommended Posts

The PHP manual says:

Request variables: $_REQUEST

 

An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE.

 

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_REQUEST; to access it within functions or methods.

 

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_REQUEST array. For related information, see the security chapter titled Using Register Globals. These individual globals are not superglobals.

 

Which is interesting, but not very helpful for me. I could really use a simple example please.

 

Thank you.

Try the following to investigate:

 

var_dump($_REQUEST);
print_r($_REQUEST);
foreach ($_REQUEST as $name => $value) {
  print "$name has value $value\n";
}

 

Then call your script with some arguments, for example

 

http://domain.com/script.php?something=this&another=somethingelse

 

$_REQUEST will also include posted variables and cookies, in addition to GET variables (which is what is used in the example url above)

The PHP manual says:

Request variables: $_REQUEST

 

An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE.

 

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_REQUEST; to access it within functions or methods.

 

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_REQUEST array. For related information, see the security chapter titled Using Register Globals. These individual globals are not superglobals.

 

Which is interesting, but not very helpful for me. I could really use a simple example please.

 

Thank you.

 

what i would do is this:

 

<?php
    foreach($_REQUEST as $key => value)
    {
        echo "$key => $value<br>\n";
    }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.