【问题标题】:CodeIgniter - disallowed key characters [duplicate]CodeIgniter - 不允许的关键字符[重复]
【发布时间】:2011-03-24 17:38:33
【问题描述】:

可能重复:
CodeIgniter Disallowed Key Characters

我尝试提交的表单有点问题,它的动态和复选框值来自数据库,唯一的问题是其中一个字段有一个#,当我尝试提交时表单,它返回'disallowed key characters'。

如何才能提交#?

【问题讨论】:

  • 你能告诉我们你在这个领域的代码吗?
  • 如果重命名为"-csharp"会怎样?
  • 如果我将其重命名为它,则效果很好,唯一的问题是我为客户构建了这个系统,并且他们进入了 c#,所以我必须让它成为未来的证明:)

标签: codeigniter


【解决方案1】:

它被硬编码到函数 _clean_input_keys() 中的 Input 类中。

只需创建一个 MY_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.
*
* @access   private
* @param    string
* @return   string
*/
function _clean_input_keys($str)
{
    // if ( ! preg_match("/^[a-z0-9:_\/-]+$/i", $str)) <---- DEL
    if ( ! preg_match("/^[#a-z0-9:_\/-]+$/i", $str)) // <----INS
    {
        exit('Disallowed Key Characters.');
    }

    // Clean UTF-8 if supported
    if (UTF8_ENABLED === TRUE)
    {
        $str = $this->uni->clean_string($str);
    }

    return $str;
}

【讨论】:

    【解决方案2】:

    根据您的问题,您似乎在表单中使用 get 作为方法,因此它给出了disallowed key characters 错误。

    要允许字符#,只需将其添加到您的CONFIG 文件中 -

    $config['permitted_uri_chars'] = '\#';
    

    现在字符 # 将被允许在 url 中。

    【讨论】:

    • 我尝试将它添加到 CI 附带的默认行中,因此它最终成为 $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\#'; ...但这似乎不起作用
    【解决方案3】:

    替换:

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

    有了这个:

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

    在system/core/input.php

    【讨论】:

    • 不要覆盖核心文件。它破坏了升级
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    相关资源
    最近更新 更多