0

为了过滤 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()

任何想法?

4

3 回答 3

1

Include your file before your function is going to be called.

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

and if you are using class based function file you need to create object for that and after that you can call that function by that object. include_once('yourfilename'); $obj = new ClassName; foreach($_POST as $key => $value) { $post[$key] = $obj->filter($value); }

于 2014-04-16T07:46:00.663 回答
1

Use include or require to include a file. You can use get_included_files() function to check for files' inclusion.

于 2014-04-16T07:27:03.723 回答
0

我发现解决此问题的最佳方法是简单地再次添加它。在你的情况下是这样的:

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

然后你会收到一条新的错误消息,告诉你错误首先出现在哪里......例如“函数在文件中重新声明,行号,......等等等等”

于 2020-12-23T21:15:04.650 回答