Practical Web Data Patterns
Cookie Choices
Use a cookie-like value to choose a display preference.
Cookie Choices
cookie_choice.php
<?php
$theme = ;
$allowed = in_array($theme, ["light", "dark"], true);
$selected = $allowed ? $theme : "light";
echo "theme=" . $theme . "\n";
echo "selected=" . $selected . "\n";
<?php
$theme = ;
$allowed = in_array($theme, ["light", "dark"], true);
$selected = $allowed ? $theme : "light";
echo "theme=" . $theme . "\n";
echo "selected=" . $selected . "\n";
<?php
$theme = ;
$allowed = in_array($theme, ["light", "dark"], true);
$selected = $allowed ? $theme : "light";
echo "theme=" . $theme . "\n";
echo "selected=" . $selected . "\n";
cookie-choice
Cookies often store small preference values. A handler can validate the value and fall back to a default.