PHP Request | How to use $_REQUEST to work with Get and Post

Introduction to $_REQUEST

The PHP $_REQUEST variable is used to retrieve the information sent by POST, GET or Cookie. This information can be assigned or saved to the database or can be used for any intended purposes.

See an example of $_REQUEST with post

The post and get methods are used in forms to send data to the server. We have used PHP $_GET and $_POST as well to receive the form data for respected form method.

However, the $_REQUEST contains forms data sent by either of the methods as well as cookies.

Example of using PHP $_Request

The following example uses the Post method of the form to send data to the server. So information entered will not be visible in the address bar.

PHP request

Experience this example online



In above example, simply replace method=”get” and you will see the same output except in address bar. See example below.

The $_request example with get method

The following example is the same as above except we used the get method of form rather post to send data to the server. As such, the request is used for both get and post methods, the retrieving method remains the same.

PHP request get

Experience this example online



As you test this example, you will see the same output. However, when using the get method the entered information can be seen in the address bar of the browser.

For more on which method should be used in forms depends on the scenario you are working for.

Related: PHP Get and Post


Was this article helpful?

Related Articles

Leave A Comment?