【问题标题】:How Can I Call a Function Properly?如何正确调用函数?
【发布时间】:2014-12-18 10:40:00
【问题描述】:

代码:

$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;
}

是的,我想使用此功能过滤用户输入,我该如何正确地做到这一点? :)

【问题讨论】:

  • 您遇到什么问题? 正确地是什么意思?
  • 我以为这就是我们调用函数的方式>.echo function xss_clean_team($team);

标签: php filter xss sanitize


【解决方案1】:

通过以下代码实现

echo xss_clean_team($user);

【讨论】:

  • @AnonGuy 不,你不需要这样做。 $team 只是一个变量并将字符串值传递给函数。
  • 这有帮助。谢谢:D
猜你喜欢
  • 2020-09-27
  • 2021-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多