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.

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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";
    }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.