[ Posted by Amar Beslija ] How to use white lists in PHP. https://lab387.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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