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

 





免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM