让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);
}
}
求高手验证是否安全!! 很好,谢谢分享。只是不支持空格哦。 是啊,楼主看看能不能解决一下,空格怎么办 本帖最后由 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
sison 发表于 2011-9-1 16:18 static/image/common/back.gif
在谷歌里可以读取出汉字,但在IE里就不行了
http://localhost:8080/CI/index.php/dbtest/db_queryrows?a=d ...
这个跟 CI 无关,是浏览器的问题。 应该是编码问题吧 为什么我照办了后还是不管用呢,而且弱弱地问一句,这个代码是不是少了第一行
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
页:
[1]