最近在用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; }