Superglobals as Concepts
Server Values
$_SERVER holds request and runtime context such as the request method.
request context
Server values describe how a script is being reached, not just what data was submitted.
Server Values
server_values.php
Replay: real traced execution (multi-file project)
<?php
$method = "GET";
$_SERVER["REQUEST_METHOD"] = $method;
$_SERVER["SCRIPT_NAME"] = "/index.php";
$isPost = $_SERVER["REQUEST_METHOD"] === "POST";
$context = $method === "CLI" ? "command" : ($isPost ? "form" : "page");
echo "method=" . $_SERVER["REQUEST_METHOD"] . "\n";
echo "script=" . $_SERVER["SCRIPT_NAME"] . "\n";
echo "context=" . $context . "\n";
<?php
$method = "POST";
$_SERVER["REQUEST_METHOD"] = $method;
$_SERVER["SCRIPT_NAME"] = "/index.php";
$isPost = $_SERVER["REQUEST_METHOD"] === "POST";
$context = $method === "CLI" ? "command" : ($isPost ? "form" : "page");
echo "method=" . $_SERVER["REQUEST_METHOD"] . "\n";
echo "script=" . $_SERVER["SCRIPT_NAME"] . "\n";
echo "context=" . $context . "\n";
<?php
$method = "CLI";
$_SERVER["REQUEST_METHOD"] = $method;
$_SERVER["SCRIPT_NAME"] = "/index.php";
$isPost = $_SERVER["REQUEST_METHOD"] === "POST";
$context = $method === "CLI" ? "command" : ($isPost ? "form" : "page");
echo "method=" . $_SERVER["REQUEST_METHOD"] . "\n";
echo "script=" . $_SERVER["SCRIPT_NAME"] . "\n";
echo "context=" . $context . "\n";
$method ← GET, $_SERVER["REQUEST_METHOD"] ← GET, $_SERVER["SCRIPT_NAME"] ← /index.php
1<?php2$method→ GET = "GET"; //@method="POST", "CLI"3$_SERVER["REQUEST_METHOD"]→ GET = $methodGET;4$_SERVER["SCRIPT_NAME"]→ /index.php = "/index.php";5$isPost→ (empty) = $_SERVER["REQUEST_METHOD"]GET === "POST";6$context→ page = $methodGET === "CLI" ? "command" : ($isPost(empty) ? "form" : "page");78echo "method=" . $_SERVER["REQUEST_METHOD"]GET . "\n";9echo "script=" . $_SERVER["SCRIPT_NAME"]/index.php . "\n";10echo "context=" . $contextpage . "\n";outputmethod=GET script=/index.php context=pagevalues this stepArray$_SERVER
$method ← POST, $_SERVER["REQUEST_METHOD"] ← POST, $_SERVER["SCRIPT_NAME"] ← /index.php
1<?php2$method→ POST = "POST";3$_SERVER["REQUEST_METHOD"]→ POST = $methodPOST;4$_SERVER["SCRIPT_NAME"]→ /index.php = "/index.php";5$isPost→ 1 = $_SERVER["REQUEST_METHOD"]POST === "POST";6$context→ form = $methodPOST === "CLI" ? "command" : ($isPost1 ? "form" : "page");78echo "method=" . $_SERVER["REQUEST_METHOD"]POST . "\n";9echo "script=" . $_SERVER["SCRIPT_NAME"]/index.php . "\n";10echo "context=" . $contextform . "\n";outputmethod=POST script=/index.php context=formvalues this stepArray$_SERVER
$method ← CLI, $_SERVER["REQUEST_METHOD"] ← CLI, $_SERVER["SCRIPT_NAME"] ← /index.php
1<?php2$method→ CLI = "CLI";3$_SERVER["REQUEST_METHOD"]→ CLI = $methodCLI;4$_SERVER["SCRIPT_NAME"]→ /index.php = "/index.php";5$isPost→ (empty) = $_SERVER["REQUEST_METHOD"]CLI === "POST";6$context→ command = $methodCLI === "CLI" ? "command" : ($isPost(empty) ? "form" : "page");78echo "method=" . $_SERVER["REQUEST_METHOD"]CLI . "\n";9echo "script=" . $_SERVER["SCRIPT_NAME"]/index.php . "\n";10echo "context=" . $contextcommand . "\n";outputmethod=CLI script=/index.php context=commandvalues this stepArray$_SERVER