跟大家講解下有關CodeIgniter框架提示Disallowed Key Characters的解決辦法_PHP,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說CodeIgniter框架提示Disallowed Key Characters的解決辦法_PHP,小編也收集到了有關CodeIgniter框架提示Disallowed Key Characters的解決辦法_PHP的相關資料,希望大家看到了會喜歡。
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; }}
來源:php中文網