致命错误:调用未定义的函数过滤器()

时间:2014-04-16 07:10:57

标签: php sanitization sanitize html-sanitizing

要过滤post变量,我在包含文件中使用以下函数

function filter($post) {
    $post = trim(htmlentities(strip_tags($post)));

    if (get_magic_quotes_gpc())
        $post = stripslashes($post);

    $post = mysql_real_escape_string($post);

    return $post;
}

当我使用以下代码过滤主文件中的post数组时

foreach($_POST as $key => $value) {
    $post[$key] = filter($value); 
}

我收到了

Fatal error: Call to undefined function filter()

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

使用includerequire包含文件。您可以使用get_included_files()函数来检查文件'包含。

答案 1 :(得分:1)

在调用函数之前包含您的文件。

include_once('yourfilename'); foreach($_POST as $key => $value) { $post[$key] = filter($value); }

如果您使用的是基于类的函数文件,则需要为其创建对象,之后您可以通过该对象调用该函数。 include_once('yourfilename'); $ obj = new ClassName; foreach($_POST as $key => $value) { $post[$key] = $obj->filter($value); }

答案 2 :(得分:0)

我发现解决此问题的最佳方法是重新添加它。在你的情况下是这样的:

function filter($post) {
//do nothing.. for debugging...
}

然后您将收到一条新的错误消息,告诉您错误最初位于何处...例如“在文件中重新声明函数,行号,...等等”