$_REQUEST is a PHP superglobal variable that holds submitted form data along with all cookie data.
In essence, it is an array that combines data from $_GET, $_POST, and $_COOKIE.
You can access this data using the $_REQUEST keyword followed by the name of the form field or cookie, like this:
$_REQUEST['firstname'] |
POST requests typically involve data submitted from an HTML form.
Here’s an example of what an HTML form might look like:
HTML form
<html> <form method="post" action="demo_request.php"> </body> |
When a user clicks the submit button, the form data is sent to a PHP file specified in the action attribute of the <form>
tag.
In that PHP file, we can use the $_REQUEST
variable to retrieve the values of the input fields.
PHP file
$name
|
In the example below, we have combined the HTML form and PHP code within the same PHP file.
Additionally, we have included some extra lines for security.
<html>
<?php $name = htmlspecialchars($_REQUEST['fname']); ?>
|