我可以配置codeigniter以避免所有的问题吗?

时间:2016-05-27 00:46:15

标签: php codeigniter html-entities

我有一个巨大的codeigniter应用程序,有很多表单和字段。我需要避免用户在任何输入中输入HTML代码。我知道我可以逃脱像strip_tags这样的功能,或者使用htmlentites来逃避它。

但我想知道是否有任何方法可以全局执行,删除或转义插入整个应用程序的任何输入中的html代码。

1 个答案:

答案 0 :(得分:1)

我修改了检索结果的函数,过滤了html打开和关闭标记。这就是我想要的东西。拒绝显示保存在数据库中的html或javascript。

public function array_htmlentities(&$row){
        //return $row;
        foreach($row as &$value){
            if( is_array($value) || is_array($value) ){
                $value = $this->array_htmlentities($value);
            }elseif(is_string($value)){
                $json = json_decode($value);
                if( is_array($json) || is_array($json) ){
                    $value = json_encode($this->array_htmlentities($json));
                }else
                    $value = str_replace(array('<','>'), array('&lt;','&gt;'), $value);
                //$value = $value;
            }else
                $value = $value;
        }

        return $row;
    }
相关问题