PHP Superglobal - $_REQUEST with Examples

PHP Superglobal - $_REQUEST with Examples


This $_REQUEST variable used to access the data after submission of HTML Form. Form method can be either ‘GET’ or ‘POST’.The following example shows an input field (input) and the submit button (submit) form (form). When the user submits the form data by clicking on the "Submit" button, the form data is sent to the <form> tag in the script file specified in the action attribute. In this example, we specify a file to process the form data. If you want other PHP files to process the data, you can modify the specified script file name. We can then use the super global variable $ _REQUEST to collect field data in the form of input:

For Example :

  • In the above code we have created a form that takes the name as input from the user and and type anything in the text box and user clicks on submit button.
  • We transport the data accepted in the form to the same page using $_SERVER[‘PHP_SELF’] element as specified in the action attribute, because we manipulate the data in the same page using the PHP code.
  • The data is retrieved using the $_REQUEST superglobal array variable as shown in the statement.

                                           $name=$_REQUEST['name'];

Then it is displayed using the echo statment,

Output :