0
0
PHPprogramming~10 mins

$_REQUEST behavior in PHP - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - $_REQUEST behavior
Client sends HTTP request
Server receives request
PHP populates superglobals
$_REQUEST combines all three
Script accesses $_REQUEST values
When a PHP script runs, it collects data sent by the client via GET, POST, and COOKIE methods into separate arrays, then combines them into $_REQUEST for easy access.
Execution Sample
PHP
<?php
// URL: script.php?name=Alice
// POST data: age=30
// Cookie: city=Paris

print_r($_REQUEST);
?>
This code prints all input data from GET, POST, and COOKIE combined in $_REQUEST.
Execution Table
StepSourceData Received$_GET$_POST$_COOKIE$_REQUESTOutput
1Client sends GETname=Alice{"name":"Alice"}{}{}{"name":"Alice"}{}
2Client sends POSTage=30{"name":"Alice"}{"age":"30"}{}{"name":"Alice", "age":"30"}{}
3Client sends COOKIEcity=Paris{"name":"Alice"}{"age":"30"}{"city":"Paris"}{"name":"Alice", "age":"30", "city":"Paris"}{}
4PHP script runsAccess $_REQUEST{"name":"Alice"}{"age":"30"}{"city":"Paris"}{"name":"Alice", "age":"30", "city":"Paris"}{}
5Print $_REQUESTOutput combined array{"name":"Alice"}{"age":"30"}{"city":"Paris"}{"name":"Alice", "age":"30", "city":"Paris"}Array ( [name] => Alice [age] => 30 [city] => Paris )
💡 All input sources combined into $_REQUEST and printed.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
$_GET{}{"name":"Alice"}{"name":"Alice"}{"name":"Alice"}{"name":"Alice"}
$_POST{}{}{"age":"30"}{"age":"30"}{"age":"30"}
$_COOKIE{}{}{}{"city":"Paris"}{"city":"Paris"}
$_REQUEST{}{"name":"Alice"}{"name":"Alice", "age":"30"}{"name":"Alice", "age":"30", "city":"Paris"}{"name":"Alice", "age":"30", "city":"Paris"}
Key Moments - 3 Insights
Why does $_REQUEST contain data from $_GET, $_POST, and $_COOKIE all together?
Because PHP automatically merges these three superglobals into $_REQUEST, so you can access any input source from one array, as shown in execution_table rows 3 and 4.
If a key exists in both $_GET and $_POST, which value appears in $_REQUEST?
The value depends on PHP's variables_order configuration, but usually $_POST overrides $_GET in $_REQUEST. This is important to check in your PHP settings.
Can $_REQUEST be empty even if $_GET or $_POST have data?
Yes, if PHP's variables_order does not include 'G', 'P', or 'C', $_REQUEST might not be populated. See execution_table step 4 where $_REQUEST is built.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 3, what keys does $_REQUEST contain?
A["age", "city"]
B["name", "age"]
C["name", "age", "city"]
D["name", "city"]
💡 Hint
Check the $_REQUEST column at step 3 in the execution_table.
At which step does $_POST get its value?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the $_POST column in execution_table rows.
If the client sends no cookies, how would $_REQUEST change?
AIt would be empty
BIt would not include the 'city' key
CIt would only have 'city' key
DIt would only have 'age' key
💡 Hint
Refer to variable_tracker for $_COOKIE and $_REQUEST values.
Concept Snapshot
$_REQUEST is a PHP superglobal array
that combines $_GET, $_POST, and $_COOKIE data.
It lets you access all input sources in one place.
Order of merging depends on PHP settings.
Use it carefully to avoid conflicts.
Full Transcript
When a PHP script runs, it receives data from the client via GET parameters, POST form data, and cookies. PHP stores these separately in $_GET, $_POST, and $_COOKIE arrays. Then, PHP merges these three arrays into one called $_REQUEST. This means you can access any input data from one array instead of checking each separately. For example, if the client sends a GET parameter 'name=Alice', a POST parameter 'age=30', and a cookie 'city=Paris', then $_REQUEST will have all three keys: 'name', 'age', and 'city'. The exact order of merging depends on PHP's configuration, but usually POST overrides GET if keys clash. This behavior is shown step-by-step in the execution table and variable tracker. Understanding $_REQUEST helps you handle user input easily but be careful with key conflicts and security.