array_column() 返回input数组中键值为column_key的列, 如果指定了可选参数index_key,那么input数组中的这一列的值将作为返回数组中对应值的键。 参数 input 需要取出数组列的多维数组(或结果集) column_key 需要返回值的列,它可以是索引数组的列索引,或者是关联数组的列的键。 也可以是NULL,此时将返回整个数组(配合index_key参数来重置数组键的时候,非常管用)…
November 2, 2018
报错:CodeIgniter Disallowed Key Characters, disallowed key characters
改用一下的正则表达式
!preg_match("/^[a-z0-9\x{4e00}-\x{9fa5}\:\;\.\,\?\!\@\#\$%\^\*\"\~\'+=\\\ &_\/\.\[\]-\}\{]+$/iu", $str)
修改 Input.php
或者创建自己的 MY_Input.php
, 如下:
<?php class MY_Input extends CI_Input { /** * Clean Keys * * This is a helper function. To prevent malicious users * from trying to exploit keys we make sure that keys are * only named with alpha-numeric text and a few other items. * * Extended to allow: * - '.' (dot), * - '[' (open bracket), * - ']' (close bracket) * * @access private * @param string * @return string */ function _clean_input_keys($str) { // UPDATE: Now includes comprehensive Regex that can process escaped JSON if (!preg_match("/^[a-z0-9\:\;\.\,\?\!\@\#\$%\^\*\"\~\'+=\\\ &_\/\.\[\]-\}\{]+$/iu", $str)) { /** * Check for Development enviroment - Non-descriptive * error so show me the string that caused the problem */ if (getenv('ENVIRONMENT') && getenv('ENVIRONMENT') == 'DEVELOPMENT') { var_dump($str); } exit('Disallowed Key Characters.'); } // Clean UTF-8 if supported if (UTF8_ENABLED === TRUE) { $str = $this->uni->clean_string($str); } return $str; } } // /?/> /* Should never close php file - if you have a space after code, it can mess your life up */
++Chinese Character Support 中文支持
// NOTE: \x{4e00}-\x{9fa5} = allow chinese characters // NOTE: 'i' — case insensitive // NOTE: 'u' — UTF-8 mode if (!preg_match("/^[a-z0-9\x{4e00}-\x{9fa5}\:\;\.\,\?\!\@\#\$%\^\*\"\~\'+=\\\ &_\/\.\[\]-\}\{]+$/iu", $str)) { ... } // NOTE: When Chinese characters are provided in a URL, they are not 'really' there; the browser/OS // handles the copy/paste -> unicode conversion, eg: // 一二三 --> xn--4gqsa60b // 'punycode' converts these codes according to RFC 3492 and RFC 5891. // https://github.com/bestiejs/punycode.js --- $ bower install punycode
如果问题还是存在,那么找到system/core/Input.php
function _clean_input_keys($str) { if (!preg_match("/^[a-z0-9\x{4e00}-\x{9fa5}\:\;\.\,\?\!\@\#\$%\^\*\"\~\'+=\\\ &_\/\.\[\]-\}\{]+$/iu", $str)) { exit('Disallowed Key Characters. (' . $str . ')'); } return $str; }
在字符串 “Disallowed Key Characters.” 后面打印一下 $str,这样可以更加直观的发现问题。
本文:报错:CodeIgniter Disallowed Key Characters, disallowed key characters