Uses of PHP $_REQUEST:
- The PHP $_REQUEST is a PHP superglobal variable that is used to collect the data after submitting the HTML forms as the $_REQUEST variable is useful to read the data from the submitted HTML open forms.
- $_REQUEST is an associative array that by default contains contents of an $_GET, $_POST, and $_COOKIE.
- The variables in a $_REQUEST super variable are obtained to the HTML scripts through GET, POST, and COOKIE inputs, so it could be changed by the remotely associated user and can’t be trusted again.
- The presence $_REQUEST variable and the suited orders of $_REQUEST are variables listed in the array is declared similar to the PHP request_order, and variables_order configuration directives are it.
- PHP $_REQUEST is the featuring PHP superglobal variable which is used to collect data after submitting the HTML forms in the browser
- PHP’s $_REQUEST is widely used to collect information that is after submitting from HTML browsed forms.
- The $_REQUEST function is used to get the form information sent with its POST method and the other GET method.
Approach: The example demonstrates an HTML form with the input field and within having to submit button. When a user submits the information by clicking on the button “Submit”, the filled data is sent to the file i.e. examined with actions attributes of the <form> tag within it
We aim the file itself for preprocessing form data as we use another PHP file to preprocess a form data, replacing that with occurring filename of our choice. We use the PHP $_REQUEST super global variable to collect the value of the input field from it.
Example:
HTML
<!DOCTYPE html> < html > < body > <!--Defining Form--> < h1 style = "color:green" >neveropen</ h1 > < form method = "post" action="<?php echo $_SERVER['PHP_SELF'];?>"> Name: < input type = "text" name = "pname" > < input type = "submit" > </ form > <? php // Getting $REQUEST METHOD if ($_SERVER["REQUEST_METHOD"]=="POST") { $ name = htmlspecialchars ($_REQUEST['pname']); // Collecting the value of input field from it if (empty($name)) { echo "Name is empty"; } else { // Printing the entered data echo $name; } } ?> </ body > </ html > |
Output: