Код :
$url = $_POST['url'];
$team = $_POST['team'];
$user = $_POST['user'];
$regip = $_SERVER[REMOTE_ADDR];
$low_user = strtolower($user);
$up_user = strtoupper($user);
Функция Фильтр XSS, который я нашел в Интернете :
function xss_clean_team($team)
{
$team = str_replace(array('&','<','>'), array('&amp;','&lt;','&gt;'), $team);
$team = preg_replace('/(&#*\w+)[\x00-\x20]+;/u', '$1;', $team);
$team = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $team);
$team = html_entity_decode($team, ENT_COMPAT, 'UTF-8');
$team = preg_replace('#(<[^>]+?[\x00-\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $team);
$team = preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([`\'"]*)[\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2nojavascript...', $team);
$team = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iu', '$1=$2novbscript...', $team);
$team = preg_replace('#([a-z]*)[\x00-\x20]*=([\'"]*)[\x00-\x20]*-moz-binding[\x00-\x20]*:#u', '$1=$2nomozbinding...', $team);
$team = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i', '$1>', $team);
$team = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i', '$1>', $team);
$team = preg_replace('#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu', '$1>', $team);
$team = preg_replace('#</*\w+:\w[^>]*+>#i', '', $team);
do
{
$old_data = $team;
$team = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $team);
}
while ($old_data !== $team);
return $team;
}
Так что да, я хочу фильтровать пользовательский ввод с помощью этой функции, как я могу сделать это правильно?
🙂
Сделайте это с помощью следующего кода
echo xss_clean_team($user);
Других решений пока нет …