在 Codeigniter 中加密 uri 段
我想加密作为 ID 传递以查询数据库表的 uri 段。
例如,我正在使用
$id=urlencode($this->encrypt->encode($user['id']));
它在另一个控制器上进行解码,
$id_decrypt=$this->encrypt->decode(urldecode($id));
我已经测试了加密和解密,它似乎可以工作。但是,在尝试网址时,例如。
http://localhost/app_name/index.php/profile/view_profile/b98N98YNqoEA7yI1tavIY1s51RhiSHKGCFarU4A6XgFUMB%2BI3KwiEA23h1XITmkq1qPABqGs8e1sdP16v4og8g%3D%3D
在某些 url 上,它会按预期工作,但在某些 url 上,它会给出浏览器错误 404(未找到对象)。删除加密段后,我可以访问索引函数。造成这种情况的可能原因是什么?
I want to encrypt my uri segments that are passed as IDs to query into database tables.
For example I'm using
$id=urlencode($this->encrypt->encode($user['id']));
which is decode on another controller using
$id_decrypt=$this->encrypt->decode(urldecode($id));
I have tested the encryption and decription and it seems to work. However on trying the urls eg.
http://localhost/app_name/index.php/profile/view_profile/b98N98YNqoEA7yI1tavIY1s51RhiSHKGCFarU4A6XgFUMB%2BI3KwiEA23h1XITmkq1qPABqGs8e1sdP16v4og8g%3D%3D
on some of the url it will work as expected but on some it will give browser error 404 (Object not found). On deleting the encrypted segment, I can access the index function. What could be the possible cause of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在文件 ./application/config/config.php 中,有一个用于允许的 uri 字符的部分。默认字符是:
在某些项目中,我也更改了这一点:
但是,正如 CodeIgniter 工程师所说
Within the file ./application/config/config.php there is a section for permitted uri chars. The default characters are:
In some projects, I have changed this too:
However, as the CodeIgniter Engineers state
我认为您遇到的问题是
+
符号。%2B
解码后会变成+
。 CI 的 URL 路由器对解码后的 URL 进行操作。+
是 url 中用于表示空格的特殊字符。这可能会导致 url 路由器崩溃。更新:
这实际上可能与 CI 中的 XSS 保护脚本有关。有一个可接受的 URL 字符列表,用于检查输入。您使用的加密确实在您的输入中添加了很多有趣的字符。 (
%3D
是=
)。这些(包括+)可能就是出问题的地方。要解决此问题:
I think the problem you're having is with the
+
sign.%2B
turns into+
when decoded. The Url Router for CI operates on the decoded url.+
is a special character in urls used to represent spaces. This could be tripping up the url router.Update:
This may actually be related to the XSS Protection Script in CI. There's a list of accepted URL Characters that it checks inputs against. The encryption you're using does put lots of fun characters in your input. (
%3D
is=
). These (including +) are probably what's tripping up.To fix this: