CodeIgniter框架提示Disallowed Key Characters的解决办法_PHP

WBOY
Release: 2016-06-01 11:54:50
Original
1178 people have browsed it

CI框架

打开ci框架的源码不难发现,在ci的核心input类中有这样一个函数:

复制代码 代码如下:
function _clean_input_keys($str)
    {
        if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
        {
            exit('Disallowed Key Characters.');
        }

        // Clean UTF-8 if supported
        if (UTF8_ENABLED === TRUE)
        {
            $str = $this->uni->clean_string($str);
        }

        return $str;
}
这是进行过滤的,所以抛出错误

我们在application的core中对这个方法进行重写即可
命名一个为MY_Input.php(前缀MY_可以在config.php中自定义),然后将下面代码加入即可
复制代码 代码如下:
class AI_Input extends CI_Input {

    //构造函数
    function __construct(){
        parent::__construct();
    }

    function _clean_input_keys($str)
    {
        if(preg_match("/^,_[a-z0-9:_\/-]+$/",$str)){
            $str = preg_replace("/,_/","",$str);
        }

        if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))
        {
            exit('Disallowed Key Characters.'.$str);
        }
        return $str;
    }
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template