瀏覽頁面直接顯示 Disallowed Key Characters,清除瀏覽器快取/Cookie 後暫時恢復,不同瀏覽器表現不一。原因在於 CI 核心 Input::_clean_input_keys() 對鍵名字元過濾過嚴,且未對 URL 編碼後的字串正確判斷。
檔案:system/core/Input.php
function _clean_input_keys($str)
{
if (!preg_match("/^[a-z0-9:_\/-]+$/i", $str)) {
exit('Disallowed Key Characters.');
}
// ... UTF-8 清理 ...
return $str;
}
function _clean_input_keys($str)
{
$config =& get_config('config');
// 使用設定檔許可字元,並對 rawurlencode 後的字串比對
if (!preg_match("/^[".$config['permitted_uri_chars']."]+$/i", rawurlencode($str))) {
exit('Disallowed Key Characters.');
}
// ... UTF-8 清理 ...
return $str;
}
permitted_uri_chars 預設為 a-z 0-9~%.:_-,可在 config/config.php 自訂rawurlencode() 會將特殊字元編碼(如空格→%20),使後續正則能正確判斷原始鍵名是否合法在 config/config.php 擴大許可字元範圍(風險自負):
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\s\u4e00-\u9fa5'; // 含中文
或覆寫 MY_Input 類別(CI 3.x 建議做法)。