如何更改codeigniter中显示的错误

fab*_*bbb 2 php codeigniter

The URI you submitted has disallowed characters.

我如何拦截此错误?他们的callback_功能是什么?当我尝试在URL中使用=时,会发生此错误.例如,我把1 = 1 - 我得到这个错误.而不是我想要的错误页面redirect('main/cate/page');

如何捕获此错误并重定向而不是显示"遇到错误页面"

Jor*_*eno 6

看起来错误正在被抛出system/core/URI.php.幸运的是,您可以扩展核心类.在application/core被调用中创建一个文件MY_URI.php并覆盖该函数:

class MY_URI extends CI_URI{
    function __construct(){
        parent::__construct();
    }
    function _filter_uri($str){
        if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
        {
            // preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
            // compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
            if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
            {
                redirect('main/cate/page');
            }
        }

        // Convert programatic characters to entities
        $bad    = array('$',        '(',        ')',        '%28',      '%29');
        $good   = array('$',    '(',    ')',    '(',    ')');

        return str_replace($bad, $good, $str);
    }
}
Run Code Online (Sandbox Code Playgroud)