Forum Moderators: coopster
foreach ($_GET as $k => $v) {
$_GET[$k] = htmlentities($v, ENT_QUOTES);
} strip_tags() work just as effectively without encoding special chars? echo <a href="?' . $_GET['id'] . '">click</a> page.php?id=45 followed by "><script>alert('hallo')</script><foo=" For outputting variable information as html, strip_tags will ensure the user isn't trying to pass html into your process and htmlspecialchars() should be enough when it is embedded in an element to encode special characters
<input name="msg" value="<?php echo $_POST['msg'] ?>"> <p><?php echo $_POST['msg'] ?></p> just in case you are wondering, i am meticulous about filtering/escaping mysql input.
<select id="neighborhood" name="neighborhood">
<option value="1">Downtown</option>
<option value="2">Manhattan</option>
<option value="3">Upper West Side</option>
</select>
$expected_vals = array(
0 => true,
13 => true,
'string_key' => true
);
if(isset($expected_vals[$_POST['select_menu']])) {
// some processing
} else {
$errors[] = htmlentities($_POST['select_menu'], ENT_QUOTES) . ' is not a valid input.';
}
And then I can do
......
$errors[] = htmlentities($_POST['select_menu'], ENT_QUOTES) . ' is not a valid input.';
.......