kasindy 发表于 2011-6-29 14:31:48

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

本帖最后由 kasindy 于 2011-6-29 14:32 编辑

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


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);
      }

}


求高手验证是否安全!!

avinmo 发表于 2011-8-27 14:34:09

很好,谢谢分享。只是不支持空格哦。

sison 发表于 2011-9-1 16:09:16

是啊,楼主看看能不能解决一下,空格怎么办

sison 发表于 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

Hex 发表于 2011-9-1 17:17:42

sison 发表于 2011-9-1 16:18 static/image/common/back.gif
在谷歌里可以读取出汉字,但在IE里就不行了

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

这个跟 CI 无关,是浏览器的问题。

13880411700 发表于 2011-11-2 15:14:30

应该是编码问题吧

静影沉璧 发表于 2012-4-27 11:35:51

为什么我照办了后还是不管用呢,而且弱弱地问一句,这个代码是不是少了第一行
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
页: [1]
查看完整版本: 让ci 2.0 支持url中文的最简单方法