|
楼主 |
发表于 2017-3-28 16:24:48
|
显示全部楼层
Hex管理员谢谢,这个问题已经解决了,是ci配置中 config.php 文件中这一行 $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; ci对请求的地址的uri做了筛选限制,解决办法是在 application/core/ 目录中添加一个 MY_URI.php 继承重写 system/core/URI.php 的筛选uri 方法 _filter_uri,
MY_URI.php 文件如下
PHP复制代码 <?php
if (! defined ( 'BASEPATH' ))
exit ( 'No direct script access allowed' );
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) {
$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 );
}
$bad = array ('$', '(', ')', '%28', '%29' );
$good = array ('$', '(', ')', '(', ')' );
return str_replace ( $bad, $good, $str );
}
private function _detect_uri () {
if (! isset ( $_SERVER ['REQUEST_URI'] ) or ! isset ( $_SERVER ['SCRIPT_NAME'] )) {
return '';
}
//$uri = $_SERVER ['REQUEST_URI'];
$uri = $_SERVER["PHP_SELF"];
var_dump($uri);
if (strpos ( $uri, $_SERVER ['SCRIPT_NAME'] ) === 0) {
$uri = substr ( $uri, strlen ( $_SERVER ['SCRIPT_NAME'] ) );
} elseif (strpos ( $uri, dirname ( $_SERVER ['SCRIPT_NAME'] ) ) === 0) {
$uri = substr ( $uri, strlen ( dirname ( $_SERVER ['SCRIPT_NAME'] ) ) );
}
// This section ensures that even on servers that require the URI to be in the query string (Nginx) a correct
// URI is found, and also fixes the QUERY_STRING server var and $_GET array.
if (strncmp ( $uri, '?/', 2 ) === 0) {
$uri = substr ( $uri, 2 );
}
$parts = preg_split ( '#\?#i', $uri, 2 );
$uri = $parts [0];
if (isset ( $parts [1] )) {
$_SERVER ['QUERY_STRING'] = $parts [1];
parse_str ( $_SERVER ['QUERY_STRING'], $_GET );
} else {
$_SERVER ['QUERY_STRING'] = '';
$_GET = array ();
}
if ($uri == '/' || empty ( $uri )) {
return '/';
}
$uri = parse_url ( $uri, PHP_URL_PATH );
// Do some final cleaning of the URI and return it
return str_replace ( array ('//', '../' ), '/', trim ( $uri, '/' ) );
}
} 复制代码
添加完这个文件后,不用改config.php,之前的地址就可以访问了 |
评分
-
查看全部评分
|