codeigniter - CodeIgniter不允许的关键字符

标签 codeigniter

CodeIgniter给我一个Disallowed Key Characters错误。我已将其范围缩小为表单字段的名称属性:name='prod[50-4121.5]',但不确定如何处理。

最佳答案

问题是您正在使用标准正则表达式中未包含的字符。用这个:

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

++汉字支持
// 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

关于codeigniter - CodeIgniter不允许的关键字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4197976/

相关文章:

PHP:为数组中的每个帖子添加评论计数

mysql - 巨大的SQL语句优化

php - 最佳实践 : Models and Controllers

javascript - ForEach 循环内的倒数计时器 PHP

javascript - 如何在 amcharts 的周期选择器中显示日历 View ?

php - Codeigniter $this->db->order_by (' ' ,'desc' ) 结果不完整

php - 为 Codeigniter 设置 BaseURL

php - 如何在 codeigniter 中隐藏提交按钮

javascript - ajax成功后window.location.href不工作

javascript - 我在 jquery 中的 css 不起作用 codeigniter