Codeigniter挂钩允许输入的字符

时间:2014-01-09 09:44:16

标签: php codeigniter hook

默认情况下,codeigniter不允许将所有类型的字符传递给输入$_POST/$_GET

现在,我想写一个钩子来处理这个,以允许更多的字符。但我没有什么钩点使用。有谁知道怎么写这样的钩子?感谢。

这是codeIgniter默认函数,用于处理输入允许的字符。

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

        }

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

        return $str;
    }

1 个答案:

答案 0 :(得分:0)

如果你想在url中允许更多的字符,你只需要编辑你在config/config.php找到的URI允许的字符列表

你在这里:

/*
|--------------------------------------------------------------------------
| Allowed URL Characters
|--------------------------------------------------------------------------
|
| This lets you specify with a regular expression which characters are permitted
| within your URLs.  When someone tries to submit a URL with disallowed
| characters they will get a warning message.
|
| As a security measure you are STRONGLY encouraged to restrict URLs to
| as few characters as possible.  By default only these are allowed: a-z 0-9~%.:_-
|
| Leave blank to allow all characters -- but only if you are insane.
|
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
*/
$config['permitted_uri_chars'] = 'a-z 0-9%.:_\-#'; 

然后,只要您想扩展诸如输入库之类的库,就必须创建一个名为class MY_Input extends CI_Input{ }的新库

here everything you need to know;)