我正在使用 CodeIgniter PHP 框架。我使用 JS 动态加载一个 PHP 页面:
$('someIFrame').writeAttribute(
'src',
'/index.php/controller/method/' +
escape(userGeneratedString)
);
当我运行它时,CodeIgniter 给我这个错误:
http://192.168.0.81/index.php/controller/method/dude%27s%20face
An Error Was Encountered
The URI you submitted has disallowed characters.
这是完全不正确的,因为有问题的 URL 不包含任何不允许的字符。我的配置文件允许该 URL 中存在的所有字符:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@\-';
所以我很沮丧,只允许所有字符来防止错误。
// Leave blank to allow all characters -- but only if you are insane.
// DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
//$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@\-';
$config['permitted_uri_chars'] = '';
这行上面的警告信息听起来很吓人。允许所有字符可能会出什么问题?我会被黑客入侵吗?
最佳答案
codeigniter 中的 url 是 urldecoded ,因此 %27
转换为 '
,它不在您允许的字符列表中,因此触发了错误。所以你需要允许字符一旦解码。
换句话说,当 codeigniter 看到您 %27
时,它已经被解码为 '
。
关于javascript - 在 CodeIgniter 中允许 URL 中的任何字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4170418/