• Debugging Tip: “Disallowed Key Character” Error In CodeIgniter


    关于这个错误。看到有人直接修改了 Input.php 。觉得不妥,查阅了一下,一个令我满意的答案是

    After 6 hours of massive anxiety, stress, near tears, one pound on my desk, and some hair pulling, I tracked down the source of a nagging Disallowed Key Character error that I received while using CodeIgniter: an extra line break.

    The line feed (LF) and carriage return (CR) characters (and their hex code equivalents (%0D and %0A) are forbidden in CodeIgniter’s framework. The hard part is tracking down exactly where that extra line break character lives.

    In my case, there was an extra line of blank, barren, not-all-that-obvious white space at the very, very end of one of my controller files, just after the closing ?>.

     

    所以这是一个编程习惯的问题,so,

    delete *anything* after the closing ?> -- including white space and line breaks -- or remove the ?>.

    如果你想搞清楚哪个字符的问题,可以尝试这样

    In the core CI code in system/libraries is a file called input.php I made a small modification to that file so that it would show the actual data in question.

    Around line number 199

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

    return $str;
    }

    另外一种情况,disallowed characters in a POST array

    In my case, I had single-quotes as part of the variable name. My fingers mixed up PHP array syntax and HTML form syntax.

    <!-- will cause the error -->
    <input type="text" name="fieldname['foo']" value=""> 
    
    <!-- won't cause the error. besides, this is the proper syntax. -->
    <input type="text" name="fieldname[foo]" value="">
    

    kalodont points out this can also happen when using accented characters, such as ó or ñ as keys in your array.

  • 相关阅读:
    Mac 安装FFMpeg 与 FFmpeg 格式转换
    django channels
    python3 coroutine
    python中关于sql 添加参数
    python导包的问题
    python中的列表
    django中用model生成数据库表结构
    docker
    博客大神地址
    Bean复制的几种框架性能比较(Apache BeanUtils、PropertyUtils,Spring BeanUtils,Cglib BeanCopier)
  • 原文地址:https://www.cnblogs.com/leonbond/p/2550919.html
Copyright © 2020-2023  润新知