我已阅读以上所有评论 - 但我认为你错过了简单的方法来做到这一点。
只是重载_filter_uri()
功能,做你想做的:
(将该文件放在应用程序/核心/ MY_URI.php)
// Normally this is not fully uppercase - but for some reason the URI filename is
Class MY_URI extends CI_URI
{
/**
* Filter segments for malicious characters
*
* @access private
* @param string
* @return string
*/
function _filter_uri($str)
{
if ($str != '' && $this->config->item('permitted_uri_chars') != '' && $this->config->item('enable_query_strings') == FALSE)
{
if (! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
{
// DO SOMETHING HERE LIKE REDIRECT OR CHANGE THE URL
}
}
// Convert programatic characters to entities
$bad = array('$', '(', ')', '%28', '%29');
$good = array('$', '(', ')', '(', ')');
return str_replace($bad, $good, $str);
}
你的问题对我感兴趣,我试着写一个解决方法,看起来像这是CodeIgniter的弱点之一,因为必须有太多的重写来完成这个。我建议你去CodeIgniter GitHub页面并提交这个问题,因为这肯定不是它应该表现的方式,因为这是一个相当普遍的任务。 –
问题是,重定向到错误页面_filter_uri($ str)的函数被调用三次甚至更多,它的主要目的是返回一个干净的URL,所以如果你应用一些逻辑而不是重定向,你会碰巧让你的代码运行3次或更多。我会更深入地研究这个问题,希望我能找到解决方案。 –
感谢队友。我已经准备好上课了,它只是一个如何最好地实施它的问题。它现在最后一天左右让我感到困惑。 :S – thatonefreeman