CodeIgniter出现Disallowed Key Characters的问题

最近在用CI的时候。在测试的时候有时候返回:Disallowed Key Characters ,如果清空游览器会好,但如果有多用户登录后会经常出现。搜索才发现是CI的Input.php的处理有问题。

需要修改Input.php的地方如下:

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

这里修改成如下:

function _clean_input_keys($str)
    {
         $config = &get_config('config');  
         if (!empty($config['permitted_uri_chars']))
          {
             if (!preg_match("/^[".$config['permitted_uri_chars']."]+$/i", rawurlencode($str)))   
             {   
                 exit('Disallowed Key Characters.');   
             }
          }
    // Clean UTF-8 if supported
        if (UTF8_ENABLED === TRUE)
        {
            $str = $this->uni->clean_string($str);
        }
return $str;   
    }

然后把 config/config.php 里面的:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

修改成

$config['permitted_uri_chars'] = '';

就没出现这问题了。

见:http://www.kukaka.org/home/content/576

 

或不用Config.php的配置。直接修改这正则表达式:
/^[a-z0-9:_\/|-]+$/i  在/后面加一个| 

见: http://ooxx.me/codeigniter-disallowed-key-characters.orz

 

或:http://www.nowamagic.net/librarys/veda/detail/1699

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

 




转载于:https://www.cnblogs.com/myx/archive/2013/04/16/CodeIgniter-Disallowed-Key-Characters.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值