CodeIgniter不允许的关键字符

CodeIgniter给我一个Disallowed Key Characters错误。 我已经缩小到表单字段的name属性: name='prod[50-4121.5]'但我不知道该怎么办。

问题是你正在使用不包含在标准正则expression式中的字符。 用这个:

!preg_match("/^[a-z0-9\x{4e00}-\x{9fa5}\:\;\.\,\?\!\@\#\$%\^\*\"\~\'+=\\\ &_\/\.\[\]-\}\{]+$/iu", $str)

根据评论(和个人经验),你不应该修改他们的Input.php文件 – 而是,你应该创build/使用自己的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 */ 

++汉字支持

 // 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 

打开libraries/Input.php (CI版本2.0+中的system/core/Input.php )并findfunction _clean_input_keys($str){ ,整个块应该看起来像这样:

 function _clean_input_keys($str) { if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters.'); } return $str; } 

修改PCRE,它允许新的字符。

请不要错过的字符是. (点),你应该永远逃脱. (点)在正则expression式中,否则将允许任何单个字符。

 /^[a-z0-9:_\/-\.]+$/i 

要将CodeIgniter与jQuery Ajax一起使用,请使用“Object”作为数据而不是Querystring,如下所示:

 $.ajax({ url: site_url + "ajax/signup", data: ({'email': email, 'password': password}), //<--- Use Object type: "post", success: function(response, textStatus, jqXHR){ $('#sign-up').html(response); }, error: function(jqXHR, textStatus, errorThrown){ console.log("The following error occured: "+ textStatus, errorThrown); } }); 

PHP会评估你在[]括号之间写的内容。

 $foo = array('eins', 'zwei', 'apples', 'oranges'); var_dump($foo[3-1]); 

会产生string(6) "apples" ,因为它返回$ foo [2]。

如果你想把它作为一个string,在它周围放置引号。

从包含“&”符号的富文本编辑器发送数据时,出现此错误。 使用%26replace“&”符号 – &符号的URL编码 – 解决了问题。 我也发现这样configuration的jQuery ajax请求神奇地解决了这个问题:

 request = $.ajax({ "url": url, type: "PUT", dataType: "json", data: json }); 

对象json是一个惊喜,惊喜,一个JSON对象包含一个属性值包含&符。

 function _clean_input_keys($str) { if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) { exit('Disallowed Key Characters.'); } return $str; } 

请添加。$ str退出('不允许的关键字符'。 像:exit('Disallowed Key Characters。'。$ str);

帮助您searchstream氓错误。

我发布了一个表格后,发生了同样的错误。 我只是错过了我的input名称属性之一的开幕报价。 我有:

<input name=first_name">

修复,摆脱了错误。

打开libraries/Input.phpCI version 2.0+ system/core/Input.php )并find函数_clean_input_keys($str){

修改if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str))if ( ! preg_match("/^[a-z0-9:_\-|]+$/i", $str))

法国特色人物,我也有同样的问题。 如果有人需要,这是我的class级。 它必须保存在这里:/application/core/MY_Input.php

(这个扩展也会报告巫婆性格是不允许的)

类MY_Input扩展CI_Input { 

function __construct() { parent::__construct(); } /** * 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. * * @access private * @param string * @return string */ function _clean_input_keys($str) { if ( ! preg_match("/^[a-z0-9:_\/-àâçéèêëîôùû]+$/i", $str)) { exit('Disallowed Key Characters : '.$str); } // Clean UTF-8 if supported if (UTF8_ENABLED === TRUE) { $str = $this->uni->clean_string($str); } return $str; }

}

阅读关于核心类扩展的友好手册: http : //ellislab.com/codeigniter/user-guide/general/core_classes.html

步骤1。 在/system/core/Input.php上search函数_clean_input_keys

第2步。 修改这一行

退出('不允许的关键字符'。

退出('不允许的关键字符'。$ str);

第三步。 刷新页面以查看生成错误的字符

步骤4。 如果您需要将这些字符添加到例外列表中,只需添加到此行

if(!preg_match(“/ ^ [a-z0-9:_ / – ] + $ | / i”,$ str))

我加| | (pipe道)字符在上面的例子

我发布了一个表格后,发生了同样的错误。 他们有我的input名称属性的空间。 input名称='first_name'

修复,摆脱了错误。

在我的情况下,我使用jquery serialize()序列化input表单,然后使用encodeURIComponent()对其进行urlen编码。

 var datas = form.serialize(); encodeURIComponent(datas); $.getJSON(url,datas,function(){}); 

并且codeigniter正在给出不允许的字符错误。

我认为这里的问题是,jquery serialize给出了一个编码输出,我再次用encodeURIcomponent编码它是不必要的,当codeingiter解码它时,它并没有得到实际的string,因为某些部分被编码了两次。 我会用一个例子来解释它。

 string: quantity[]=1&option=sell urlencoded while serializing: quantity%5B%5D%3D1%26option%3Dsell again urlencoded with encodedURICompontent(): quantity%255B%255D%253D1%2526option%253Dsell 

—在codeigntier

 urldecode: quantity%5B%5D=1&option=sell 

根据input类正则expression式,已经禁止了构造器。

注意:这不是对这个问题的答案,但将有助于检查是否遇到这个错误…谢谢。

在Ubuntu中,您可以通过清除浏览器的cookies来解决问题。 我有同样的问题,并通过这种方式解决。

花了一段时间来弄清楚这一个。 似乎我们大多数人错过了明显的错误…最后的“ – ”没有逃脱。

添加。 和| 正如我已经看到其他build议可能会为你工作,但正则expression式应该是:

 if ( ! preg_match("/^[a-z0-9:_\/\-\.|]+$/i", $str)) 

当我试图发送一个表单时,我看到了这个错误,并且在其中一个字段的名称中,我让这个单词“endereço”。

 echo form_input(array('class' => 'form-control', 'name' => 'endereco', 'placeholder' => 'Endereço', 'value' => set_value('endereco'))); 

当我改变'c'为'c'时,错误消失了。

我有这个问题,但我的问题是,我错误地在input的名称之前添加了一个空格像这样:

 <input type="text" name=" evening_time_phone"> 

当它是这样的:

 <input type="text" name="evening_time_phone"> 

我引用的错误是在system / libraries / Input.php中生成的(关于第215行 – 寻找函数_clean_input_keys($ str))。

那里的正则expression式不允许索引中的点字符。 我改变了,所以它会。

我有同样的问题,我发现它是在某种程度上改变的电子邮件地址的域名._ name@domain.com

根据我的经验,这可能是由不完整的语法造成的,如:

 $('#teks').val 

代替

 $('#teks').val() 

在_clean_input_keys函数中replace下面的代码

  if ( ! preg_match("/^[a-z0-9:_\/-]+$|/i", $str)) { exit('Disallowed Key Characters.\n'); } if (UTF8_ENABLED === TRUE) { $str = $this->uni->clean_string($str); } return $str;