Loading

$_REQUEST Super global variable

$_REQUEST  is an HTTP Request global variable, which collects data after submitting the HTML form.

$_REQUEST is available in all scopes throughout a script.

$_REQUEST is an associative array.

$_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms.

In PHP version 7.0 with the default settings.+, $_REQUEST array does not contain cookies.

For Example:-

<form method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’];?>”>

Name: <input type=”text” name=”name”>

<input type=”submit” value=”Request Method”>

</form>

<?php

if ($_SERVER[“REQUEST_METHOD”] == “POST”) {

$name = $_REQUEST[‘name’];

echo $name;

}

}

?>

Similarly:-

<form method=”get” action=”<?php echo $_SERVER[‘PHP_SELF’];?>”>

Name: <input type=”text” name=”name”>

<input type=”submit” value=”Request Method”>

</form>

<?php

if ($_SERVER[“REQUEST_METHOD”] == “GET”) {

$name = $_REQUEST[‘name’];

echo $name;

}

}

?>

So, $_REQUEST will use $_Get if GET is written for the method and $_REQUEST will use $POST if POST is written in the method.

Hence, The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

Share with:


Leave a Reply

Connect with:

z35W7z4v9z8w
Verified by ExactMetrics