Superglobals as Concepts
Cookie Values
$_COOKIE represents small values that the browser can send with later requests.
remembered preference
Cookies are often used for small preferences such as a display theme.
Cookie Values
cookie_values.php
Replay: real traced execution (multi-file project)
<?php
$themeInput = "light";
$_COOKIE["theme"] = $themeInput;
$theme = $_COOKIE["theme"] ?? "light";
$background = match ($theme) {
"dark" => "black",
"contrast" => "yellow",
default => "white",
};
echo "theme=" . $theme . "\n";
echo "background=" . $background . "\n";
<?php
$themeInput = "dark";
$_COOKIE["theme"] = $themeInput;
$theme = $_COOKIE["theme"] ?? "light";
$background = match ($theme) {
"dark" => "black",
"contrast" => "yellow",
default => "white",
};
echo "theme=" . $theme . "\n";
echo "background=" . $background . "\n";
<?php
$themeInput = "contrast";
$_COOKIE["theme"] = $themeInput;
$theme = $_COOKIE["theme"] ?? "light";
$background = match ($theme) {
"dark" => "black",
"contrast" => "yellow",
default => "white",
};
echo "theme=" . $theme . "\n";
echo "background=" . $background . "\n";
$themeInput ← light, $_COOKIE["theme"] ← light, $theme ← light
1<?php2$themeInput→ light = "light"; //@themeInput="dark", "contrast"3$_COOKIE["theme"]→ light = $themeInputlight;4$theme→ light = $_COOKIE["theme"]light ?? "light";5$background→ white = match ($themelight) {6 "dark" => "black",7 "contrast" => "yellow",8 default => "white",9};1011echo "theme=" . $themelight . "\n";12echo "background=" . $backgroundwhite . "\n";outputtheme=light background=whitevalues this stepArray$_COOKIE
$themeInput ← dark, $_COOKIE["theme"] ← dark, $theme ← dark, $background ← black
1<?php2$themeInput→ dark = "dark";3$_COOKIE["theme"]→ dark = $themeInputdark;4$theme→ dark = $_COOKIE["theme"]dark ?? "light";5$background→ black = match ($themedark) {6 "dark" => "black",7 "contrast" => "yellow",8 default => "white",9};1011echo "theme=" . $themedark . "\n";12echo "background=" . $backgroundblack . "\n";outputtheme=dark background=blackvalues this stepArray$_COOKIE
$themeInput ← contrast, $_COOKIE["theme"] ← contrast, $theme ← contrast
1<?php2$themeInput→ contrast = "contrast";3$_COOKIE["theme"]→ contrast = $themeInputcontrast;4$theme→ contrast = $_COOKIE["theme"]contrast ?? "light";5$background→ yellow = match ($themecontrast) {6 "dark" => "black",7 "contrast" => "yellow",8 default => "white",9};1011echo "theme=" . $themecontrast . "\n";12echo "background=" . $backgroundyellow . "\n";outputtheme=contrast background=yellowvalues this stepArray$_COOKIE