ci3.0 url中文如何解决
网上搜索了很多方案都不能解决url中文问题,始终提示The URI you submitted has disallowed characters.求解决本帖最后由 aneasystone 于 2015-7-16 10:16 编辑
在你的 application/config/config.php 文件中找到 permitted_uri_chars 配置:
$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 中的字符,但是并不建议你这样做。 1、在application/core/里面建立 MY_URI.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里面的
$config ['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
改为
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\+\-';
可以吗?
一、我新学 ci,直接就学的3.0,如果想让URL参数支持中文,需要以下第一步,第二步默认就是那样的。
1、 application\config\config.php,permitted_uri_chars改为:$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\x{4e00}-\x{9fa5}';
2、application\config\config.php,charset 保证为UTF-8(默认就是UTF-8)
然后,在需要接收参数的地方,urldecode 一下即可。
二、实际效果见附件(居然不能插入图片)
页:
[1]