用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6163|回复: 6
收起左侧

[URL] 让ci 2.0 支持url中文的最简单方法

[复制链接]
发表于 2011-6-29 14:31:48 | 显示全部楼层 |阅读模式
本帖最后由 kasindy 于 2011-6-29 14:32 编辑

以下代码保存为MY_URI.php 放在application\core 里即可

PHP复制代码
 
class MY_URI extends CI_URI {
        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
                        $str = urlencode($str); // 增加的代码
                        if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str))
                        {
                                show_error('The URI you submitted has disallowed characters.', 400);
                        }
                        $str = urldecode($str); // 增加的代码
                }
 
                // Convert programatic characters to entities
                $bad        = array('$',                '(',                ')',                '%28',                '%29');
                $good        = array('$',        '(',        ')',        '(',        ')');
 
                return str_replace($bad, $good, $str);
        }
 
}
 
复制代码


求高手验证是否安全!!
发表于 2011-8-27 14:34:09 | 显示全部楼层
很好,谢谢分享。只是不支持空格哦。
发表于 2011-9-1 16:09:16 | 显示全部楼层
是啊,楼主看看能不能解决一下,空格怎么办
发表于 2011-9-1 16:18:51 | 显示全部楼层
本帖最后由 sison 于 2011-9-1 16:20 编辑

在谷歌里可以读取出汉字,但在IE里就不行了

http://localhost:8080/CI/index.php/dbtest/db_queryrows?a=d3144&b=汉字sgagsghello测长寿试汉346363汉字

使用 echo $_GET['b'] 显示:sgagsghelloⳤԺ346363

谷哥里是正常的

CI版本是2.02
发表于 2011-9-1 17:17:42 | 显示全部楼层
sison 发表于 2011-9-1 16:18
在谷歌里可以读取出汉字,但在IE里就不行了

http://localhost:8080/CI/index.php/dbtest/db_queryrows?a=d ...

这个跟 CI 无关,是浏览器的问题。
发表于 2011-11-2 15:14:30 | 显示全部楼层
应该是编码问题吧
发表于 2012-4-27 11:35:51 | 显示全部楼层
为什么我照办了后还是不管用呢,而且弱弱地问一句,这个代码是不是少了第一行
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

本版积分规则