php CodeIgniter 中的“不允许的关键字符”错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8114512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:59:16  来源:igfitidea点击:

"Disallowed Key Character" error in CodeIgniter?

phpcodeigniter

提问by osos

Possible Duplicate:
CodeIgniter Disallowed Key Characters

可能的重复:
CodeIgniter 不允许的关键字符

When I check all the checkboxes (code below) it gives me this error:

当我检查所有复选框(下面的代码)时,它给了我这个错误:

Disallowed Key Character

不允许的关键字符

Here's my HTML:

这是我的 HTML:

<label>Stability Control </label><input type="checkbox" class="largercheckbox"   name="checkBox[Stability-Control]"></input><br/>
<label>Xenon Headlamps</label><input type="checkbox" class="largercheckbox" name="checkBox[Xenon-Headlamps]"></input><br/>

What's the problem here? I think my config file permits those characters:

这里有什么问题?我认为我的配置文件允许这些字符:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

回答by Ben Swinburne

The following function found in system/core/Input.phpdisallows the characters.

中发现的以下功能system/core/Input.php不允许使用字符。

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

This will allow a-z A-Z 0-9 : _ \ / -

这将允许 az AZ 0-9 : _ \ / -

You should extend the Input class by creating a MY_Input.php file in /application/core/and recreate the method and add any characters you wish to allow. See Creating Core System Classesfor an example as to how to achieve this.

您应该通过在其中创建一个 MY_Input.php 文件来扩展 Input 类/application/core/并重新创建该方法并添加您希望允许的任何字符。有关如何实现此目标的示例,请参阅创建核心系统类

However you should be careful with this as you could open up unnecessary security holes. You are better off rewriting your form so that it passes the existing validation.

但是,您应该小心这一点,因为您可能会打开不必要的安全漏洞。你最好重写你的表单,让它通过现有的验证。

Edit: This articledescribes both the problem and a solution as described above by extending the Input class.

编辑:本文通过扩展 Input 类来描述上述问题和解决方案。

Having searched, the following posts also demonstrate how this is accomplished to solve the same issue

搜索后,以下帖子还演示了如何完成此操作以解决相同的问题

回答by osos

Ok here is my answer

好的,这是我的答案

You have to go first to system/core/Input.php and look for a function called

你必须先去 system/core/Input.php 并寻找一个叫做

_clean_input_keys($str)

I was don't know what is the character that is disallowed here so when you add the $strlike the following

我不知道什么是当你添加了这里,所以不允许的字符$ STR像下面

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

you will get exactly the character that cause the problem mine was ' ) 'so you have to do one of the following remove the disallowed character from the html or permit it like @Ben Swinburne said

您将获得导致我的问题的确切字符是“)”,因此您必须执行以下操作之一从 html 中删除不允许的字符或允许它像@Ben Swinburne 所说的那样

Hope that help others

希望能帮助别人