php Codeigniter 重定向 -- 您提交的 URI 包含不允许使用的字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19297433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Codeigniter Redirect -- The URI you submitted has disallowed characters
提问by subrui
When i'm trying to redirect to other website, i receive this error:
当我尝试重定向到其他网站时,我收到此错误:
A PHP Error was encountered
遇到 PHP 错误
Severity: Warning
严重性:警告
Message: parse_url(/%22**) [function.parse-url]: Unable to parse URL
消息:parse_url(/%22* *) [function.parse-url]:无法解析 URL
Filename: core/URI.php
文件名:core/URI.php
Line Number: 219
行号:219
An Error Was Encountered
遇到错误
The URI you submitted has disallowed characters.
所提交的网址带有不被接受的字符。
This is all the code i have in URI.php
这是我在 URI.php 中的所有代码
private function _detect_uri()
{
if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME']))
{
return '';
}
$uri = $_SERVER['REQUEST_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, '/'));
}
回答by Suvash sarker
CodeIgniter checks all URI
segments for disallowed characters. This happens by white listing allowed characters. Which ones are allowed can be checked in /system/application/config/config.php
in the $config['permitted_uri_chars']
variable. permitted_uri_chars
are the characters that CodeIgniter accepts in your URI.The default value is set to something like.
CodeIgniter 检查所有URI
段中是否有不允许使用的字符。这是通过将允许的字符列入白名单来实现的。可以/system/application/config/config.php
在$config['permitted_uri_chars']
变量中签入哪些允许。permitted_uri_chars
是 CodeIgniter 在您的 URI 中接受的字符。默认值设置为类似的值。
$config['permitted_uri_chars'] = 'a-z 0-9~%.:&_\-';
By default only these are allowed: a-z 0-9~%.:_-
默认情况下只允许这些: a-z 0-9~%.:_-
Leave blank to allow all characters -- but only if you are insane.
留空以允许所有字符——但前提是你疯了。
%22
comes for "
.You can add this in permitted_uri_chars
list.
%22
来为"
。您可以将其添加到permitted_uri_chars
列表中。
回答by Nil'z
Try this may help but is not recommended
, in your application/config/config.php
change:
尝试这可能会有所帮助,但not recommended
在您的application/config/config.php
更改中:
$config['permitted_uri_chars'] = ''; #keep it blank to allow all characters
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
回答by Rafael Xavier
In my case it was a mal-formed URL.
就我而言,这是一个格式错误的 URL。
It was like mydomain/route¶m=1
它就像 mydomain/route¶m=1
Be aware that it should have an interrogation character instead of an "&" at the first parameter.
So it should be like this:
mydomain/route?param=1&other=2&another=3
请注意,它的第一个参数应该有一个询问字符而不是“&”。所以它应该是这样的:
mydomain/route?param=1&other=2&another=3