yunnysunny 发表于 2010-6-20 23:40:12

codeigniter1.7.2在xampp1.7.3上的兼容性

xmapp1.7.3上运行CI1.7.2,你会发现除了首页外都会报这个错误“The URI you submitted has disallowed characters.”,一看就知道是URI中出现了非法字符,之前我们见到此问题最常见的原因就是使用了中文,为此论坛上也有很多解决方案,比如http://codeigniter.org.cn/forums/thread-837-1-1.html。但是我的项目中并未出现任何非法字符,在低版本的xampp上运行一点问题也没有,换到xampp1.7.3上就出问题。经过一番探索,发现了原因的所在:xmapp1.7.3上运行下面代码

echo "|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i";

那么它输出的就是:|^+$|i,很明显把我们不想转义的部分也给转义了。所以判断条件:

if ( !preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))

始终为真,导致我们老是输出“The URI you submitted has disallowed characters.”。
解决方法呢,preg_quote是转义的意思,既然xampp无法实现正确的转义,就只好自己转义了。在config.php中设置:

$config['permitted_uri_chars'] = 'a-z 0-9~%\.\:_-u4e00-u9fa5';

在MY_URI中修改:

if ( !preg_match("|^[".$this->config->item('permitted_uri_chars')."]+$|i", $str))

yunnysunny 发表于 2010-6-20 23:41:16

当然CI中使用中文URL,还有一个比较酷的解决方案:http://codeigniter.org.cn/forums/thread-571-1-1.html
页: [1]
查看完整版本: codeigniter1.7.2在xampp1.7.3上的兼容性