如何正确调用函数?

时间:2014-12-18 10:40:00

标签: php filter xss sanitize

守则:

$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('&','<','>'), $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;
}

所以是的,我想使用此功能过滤用户输入,我该怎么做呢? :)

1 个答案:

答案 0 :(得分:0)

通过以下代码

完成
echo xss_clean_team($user);