$_REQUEST is one array that holds the contents of $_GET and $_POST (and, depending on settings, $_COOKIE).
<?php
$_GET = ["name" => "from-url"];
$_POST = ["email" => "from-form"];
// What $_REQUEST would contain, by default order "GP":
$request = array_merge($_GET, $_POST);
print_r($request);
Array
(
[name] => from-url
[email] => from-form
)
Which source wins?
If a key exists in more than one place, the order is set by the request_order setting in php.ini (or variables_order if that is empty). The usual default is "GP": GET first, then POST, and POST overwrites GET. The result depends on server configuration, so the same code can behave differently on two hosts.
Why you should avoid it
- You lose track of where data came from. A value from the URL looks the same as one from a form. Actions that should be POST-only can be triggered through a link.
- Configuration decides the behaviour, as shown above.
- It weakens CSRF protection. If a “delete” action reads
$_REQUEST["id"], an attacker can trigger it with a simple image link (GET) instead of needing a form.
Use the right array
<?php
$search = $_GET["q"] ?? ""; // reading: GET is fine
$title = $_POST["title"] ?? ""; // changing something: POST
Being explicit makes the code clear and safer.
Where you may still see it
Old scripts and some plugins use $_REQUEST to support both methods. When you meet it in someone else’s code, read the surrounding lines to learn which method is really expected.
Rule
$_GET. Changing data: $_POST. Do not use $_REQUEST in new code.