您提交的 URI 包含不允许的字符。
如何拦截此错误?他们是一个callback_
函数吗?当我尝试在 URL 中使用 = 时,会发生此错误。例如。我输入 1=1 ——我得到这个错误。我想要 redirect('main/cate/page');
如何捕获此错误并重定向而不是显示“遇到错误页面”
最佳答案
看起来错误是在 system/core/URI.php
中引发的。幸运的是,您可以extend core classes 。在 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);
}
}
关于php - 如何更改 codeigniter 中显示的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12612392/