Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
a "whitelist" is a list of acceptable values which you can compare an unknown value to, in order to be sure it is valid.
// basic concept:
$whitelist = [
if (in_array($unknown_value, $whitelist, true)) {
/* it's all good */
} else {
/* nope */
// a concrete example
$color = filter_input(INPUT_GET, 'color');
# Whitelist
$available_colors = ['red', 'orange', 'purple', 'brown'];
# Validation
if (in_array($color, $available_colors, true)) {
echo "Yes, {$color} is available";
} else {
echo 'That color is not available. Please select an available color: ', implode(', ', $available_colors);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.