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

[HELP] ci3.0 url中文如何解决

[复制链接]
发表于 2015-7-15 11:51:27 | 显示全部楼层 |阅读模式
网上搜索了很多方案都不能解决url中文问题,始终提示The URI you submitted has disallowed characters.求解决
发表于 2015-7-16 10:15:24 | 显示全部楼层
本帖最后由 aneasystone 于 2015-7-16 10:16 编辑

在你的 application/config/config.php 文件中找到 permitted_uri_chars 配置:
PHP复制代码
 
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
 
复制代码


该参数用于配置你的 URL 中允许的字符,默认情况下只允许:a-z 0-9~%.:_- 这几个字符
你的 URL 中如果含有中文,一般情况应该会被 URL 编码成类似于这种形式: %e7%bc%96%e7%a0%81,所以也不会有问题,你可以检查你的 URL 中的特殊字符是什么,是因为 URL 没有自动编码还是其他原因。如果确实需要添加特殊字符,可以在 permitted_uri_chars 参数中添加上该字符。

你也可以删除 permitted_uri_chars 参数,这样 CodeIgniter 将不再检查 URL 中的字符,但是并不建议你这样做。
发表于 2015-8-7 16:07:44 | 显示全部楼层
1、在application/core/里面建立 MY_URI.php
PHP复制代码
defined('BASEPATH') OR exit('No direct script access allowed');
 
class MY_URI extends CI_URI {
 
    public function __construct() {
        parent::__construct();
    }
    //URI过滤 允许中文
    function filter_uri($str) {
        if ($str != '' AND $this->config->item('permitted_uri_chars') != '') {
            $str = urlencode($str);
            if (!preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str) ) {
                exit('The URI you submitted has disallowed characters.');
            }
            $str = urldecode($str);
        }
        return $str;
    }
 
}
 
 
复制代码

注意:  在CI2.X里面 function _filter_uri($str) 在CI3.0里面是 function filter_uri($str)

2、将 application/config/config.php里面的
PHP复制代码
$config ['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';  
复制代码

改为
PHP复制代码
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\+\-';  
复制代码


可以吗?
发表于 2015-8-20 16:06:17 | 显示全部楼层
一、我新学 ci,直接就学的3.0,如果想让URL参数支持中文,需要以下第一步,第二步默认就是那样的。
1、 application\config\config.php,permitted_uri_chars改为:
PHP复制代码
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\x{4e00}-\x{9fa5}';
复制代码


2、application\config\config.php,charset 保证为UTF-8(默认就是UTF-8)

然后,在需要接收参数的地方,urldecode 一下即可。

二、实际效果见附件(居然不能插入图片)
QQ截图20150820160439.png

本版积分规则