array_map strip_tags $_POST, :
function post_data($name) {
global $post_cache;
if (in_array($name, $post_cache)) {
return $post_cache[$name];
}
$val = $_POST[$name];
if (is_string($val)) {
$val = strip_tags($val);
} else if (is_array($val)) {
$val = array_map('strip_tags', $val);
}
$post_cache[$name] = $val;
return $val;
}
(, , , $_POST['foo'] - foo, , ), $_POST , $_POST (unescape, ) , POST, , , POST, HTML-. , , .
In addition, it is better to sanitize the output, rather than the input. For different purposes, different methods will be required, for example, if you use
<div class="user_photo">
<img src="<?php echo photo_path($user_id) ?>" alt="<?php echo $user_name ?>" />
</div>
it $user_nameis an XSS attack vector, but strip_tagsdoes not help at all; you will need htmlspecialchars . If user data is used as a URL, you need another way to protect against javascript:URLs, etc.
source
share