_request php variable

24 April 2009

When writing in php you can set a lot of variables, and also there are a lot of pre-defined variables - such as the $_REQUEST php variable.

The $_REQUEST php variable is used to pick up any $_POST or $_GET variables. It doesn't matter whether the form has posted or sent a query string and the $_REQUEST php variable will be able to read this.

The $_REQUEST php variable, similar to the $_POST and $_GET php variables, holds an array of values that have been passed to the current page you're on.

The $_POST php variable will hold an array of all posted values to the page, the $GET php variable will hold an array of all the query string variables passed to the page and the $_REQUEST php variable will hold an array containing both $_POST and $_GET variables.

Say a form has been filled out and one of the fields is called "name". On the page where the form data has been posted to you can display this variable's value by using either $_POST['name'] or $_REQUEST['name'].

If you're submitting a form and are sending posted data and it's going to a page with a query string then it's best to use the $_REQUEST php variable as this can put all the values into one array.

When calling from the $_REQUEST php array you will need to use the same value given to the original variable name, e.g from a form it will be the name given to the <input> tag, or if it's from a query string it will be the part before the "=" symbol.

http://www.peternichol.com/entry/trackback/92/

Please leave a comment using the form provided.