qq123 2008-5-16 13:01
关于传递url 中文字符的解决方案(仅供参考)
由于CI 过滤了GET数组及URL字符串,所以在需要使用中文的地方会造成很大的不便。如果不想更改CI源代码又想在URL中传递中文,即使使用url_encode和base64_encode函数也无能为力。那么,能不能改造一下base64编码呢?下面是我的想法:
[code=PHP]function base_encode($str)
{
$src = array("/","+","=");
$dist = array("-a","-b","-c");
$old = base64_encode($str);
$new = str_replace($src,$dist,$old);
return $new;
}
function base_decode($str)
{
$src = array("-a","-b","-c");
$dist = array("/","+","=");
$old = str_replace($src,$dist,$str);
$new = base64_decode($old);
return $new;
}[/code]
下面是在浏览器中得到的效果
xOO6w6Osuf65-aiy-atL-b00Ke5-b8jnus6ho6GjoaM-c
你好,哈哈,看看效果如何。。。
artfantasy 2008-5-23 17:37
哈哈,很少用base64,没想到这编码还会出现/和+号,楼主的办法是个好办法,嘿嘿
artfantasy 2008-5-23 17:38
HEX应该把这问题提到英文官方去,让他们处理这个问题,不然这样绕弯路实在有背自由精神
archer 2008-5-30 19:25
使用最新版
修改 libraries/URI.php其中为[code] function _filter_uri($str)
{
if ($str != '' AND $this->config->item('permitted_uri_chars') != '')
{
$str=urlencode($str);
if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))
{
exit('The URI you submitted has disallowed characters.');
}
}
return $str;
}[/code]在你的控制器函数中获得相应中文字段存取变量中 再urldecode
it's work fine
pp18180058 2008-5-31 03:34
我是encodeurl后把%换成冒号:
看下面的地址
[url]http://www.d500.com.cn/index.php/search/show/:E7:9F:A2:E9:87:8F/all[/url]
Hex 2008-8-26 13:38
[quote]原帖由 [i]artfantasy[/i] 于 2008-5-23 17:38 发表 [url=http://codeigniter.org.cn/forums/redirect.php?goto=findpost&pid=3376&ptid=571][img]http://codeigniter.org.cn/forums/images/common/back.gif[/img][/url]
HEX应该把这问题提到英文官方去,让他们处理这个问题,不然这样绕弯路实在有背自由精神 [/quote]
这个我觉得很不错。
heroicq 2008-8-27 19:35
方法挺好用的啊, 有些用url为数字或字母的, 用urlencode无效,还是原样;
base64_encode会变成错误的url, 即不可读;
上面介绍的方法就解决了这个问题
heroicq 2008-8-27 19:56
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
不过上面那个 base_encode加密后位数比较后,好用!
原来这里加个 = 号就可解决, 当初都没注意到...