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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-19 我要评论
想了解CodeIgniter框架提示Disallowed Key Characters的解决办法的相关内容吗,在本文为您仔细讲解CodeIgniter Disallowed Key Characters的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:CodeIgniter,Disallowed,Key,Characters,下面大家一起来学习吧。

打开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;
    }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们