$_REQUEST lets you get data sent by a user through forms or URLs in one simple place.
$_REQUEST behavior in PHP
$_REQUEST['key']$_REQUEST is a PHP superglobal array that contains data from $_GET, $_POST, and $_COOKIE.
The order of data in $_REQUEST depends on the PHP configuration setting request_order or variables_order.
<?php // Access a value sent by GET, POST, or COOKIE $name = $_REQUEST['name']; echo "Hello, $name!"; ?>
<?php // Check if a value exists in $_REQUEST if (isset($_REQUEST['age'])) { echo "Age is " . $_REQUEST['age']; } else { echo "Age not provided."; } ?>
This program demonstrates that manually assigning values to $_GET, $_POST, and $_COOKIE inside the script does not populate $_REQUEST, as $_REQUEST is assembled from incoming HTTP request data before the script executes. In real scenarios, $_REQUEST prioritizes based on request_order (typically 'GP', so GET then POST).
<?php // Simulate GET and POST data $_GET['color'] = 'blue'; $_POST['color'] = 'red'; $_COOKIE['color'] = 'green'; // By default, request_order is usually 'GP' meaning GET then POST // But let's print what $_REQUEST['color'] gives echo "Color from $_REQUEST: " . $_REQUEST['color'] . "\n"; // To show the difference, print each superglobal echo "Color from $_GET: " . $_GET['color'] . "\n"; echo "Color from $_POST: " . $_POST['color'] . "\n"; echo "Color from $_COOKIE: " . $_COOKIE['color'] . "\n"; ?>
$_REQUEST can be slower and less secure because it mixes data sources.
It's better to use $_GET, $_POST, or $_COOKIE directly when you know where data should come from.
Check your PHP request_order setting to understand which data $_REQUEST uses first.
$_REQUEST combines GET, POST, and COOKIE data into one array.
It is easy to use but can cause confusion if you don't know the data source order.
Use it for quick access, but prefer specific superglobals for clarity and security.