The URI you submitted has disallowed characters.
我该如何拦截这个错误?他们是一个callback_
功能?当我尝试在 URL 中使用 = 时,会发生此错误。例如。我输入 1=1 ——我得到这个错误。我想要的不是错误页面redirect('main/cate/page');
如何捕获此错误并重定向而不是显示“遇到错误页面”
看起来错误被抛出system/core/URI.php
。幸运的是,你可以扩展核心类 http://codeigniter.com/user_guide/general/core_classes.html。在中创建一个文件application/core
called 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);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)