Codeigniter 不允许在 URL 中使用特定的 & 符号

Posted

技术标签:

【中文标题】Codeigniter 不允许在 URL 中使用特定的 & 符号【英文标题】:Codeigniter not allowing a specific & symbol in URL 【发布时间】:2016-10-05 20:39:51 【问题描述】:

以下 URl 会导致错误提示:“您提交的 URI 包含不允许的字符。”

http://example.com/index.php?/Paypal/success&tx=8T317791V7961045T&st=Completed&amt=20%2e00&cc=USD&cm=&item_number=

但是,如果我只是将“成功”后的 & 符号更改为 ?如下所示,尽管 URL 中还有其他 & 符号,但一切正常。这里发生了什么?

http://example.com/index.php?/Paypal/success?tx=8T317791V7961045T&st=Completed&amt=20%2e00&cc=USD&cm=&item_number=

如何才能使“成功”后的 & 符号被接受?我尝试在 Config.php 中执行以下操作,但没有成功:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-\&';

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-&';

当我尝试这个时,我得到了 404 Page Not Found 错误:

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?=&';

【问题讨论】:

你试过把$config['uri_protocol'] = 'REQUEST_URI';改成$config['uri_protocol'] = 'QUERY_STRING'; 是的,它已经是'QUERY_STRING'; 【参考方案1】:

我认为“/Paypal/success”是一个控制器 + 函数,以及将查询字符串放入 codeigniter 的正确方法 $config['index_page'] = 'index.php'; 是:

http://example.com/index.php/Paypal/success?tx=8T317791V7961045T&st=Completed&amt=20%2e00&cc=USD&cm=&item_number=

【讨论】:

【参考方案2】:

codeigniter 中的 url 是 urldecoded,因此 %27 转换为 ' ,它不在允许的字符列表中,因此触发了错误。因此,您需要允许字符一旦解码。换句话说,当 codeigniter 看到你 %27 时,它已经被解码为 '。

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@&\-!';

【讨论】:

我不确定你在说什么 Ashu,因为据我所知,链接中没有 %27 或 '。不过,我已经尝试过您的解决方案,但结果是一样的。 :( 试试这个 $config['permitted_uri_chars'] = 'a-z 0-9~%.:_+&-';

以上是关于Codeigniter 不允许在 URL 中使用特定的 & 符号的主要内容,如果未能解决你的问题,请参考以下文章

使用 PHP/CodeIgniter 动态检测动画 GIF

为啥 curl 允许使用文件 URL 方案,但不允许使用 wget

如何在 CodeIgniter URL 中允许 URI 编码字符?

我应该允许“。”在网址中?

没有斜杠的Codeigniter加密

Codeigniter .htaccess 不忽略目录