Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created November 2, 2020 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/6b26b62c3915745e18938f97d66403ce to your computer and use it in GitHub Desktop.
Save phpfiddle/6b26b62c3915745e18938f97d66403ce to your computer and use it in GitHub Desktop.
[ Posted by Amar Beslija ] How to use white lists in PHP. https://lab387.com
<html>
<head>
<title>White List</title>
<meta charset="utf-8">
</head>
<body>
<form action="" method="POST">
<label>Choose your color:</label>
<select name="color">
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="black">Not so good option</option>
</select>
<input type="submit" value="Send your color">
</form>
<?php
$colors = ["red", "blue", "green"];
if(isset($_POST["color"])){
$color = $_POST['color'];
$color = htmlspecialchars($color);
if(in_array($color, $colors)){
// Proceed with data processing
echo "Color " . $color . " is good!";
}else{
// Do not proceed with data processing
echo "Color " . $color . " is not good!";
}
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment