使用 CI 对传入 URL 进行 URL 编码
我有一个控制器,它采用 URL 作为参数。 URL 有正斜杠和查询字符串,看起来像这样:
http://example.com/foo?bar=baz&bar2=baz2
问题是,URL 来了未编码,我无法更改它。 (忘了说我实际上可以事先对 URL 进行编码,这肯定会改变一些事情)
我想在它之前对 URL 进行编码点击我的控制器,然后我想回显这个页面上的 URL。
codeigniter 是否有任何内置方法或者我需要设置什么 .htaccess
规则来处理这个问题?
I have a controller that takes a URL as a parameter. The URL has forward slashes and a query string, it looks something like this:
http://example.com/foo?bar=baz&bar2=baz2
The problem is, the URL comes in unencoded and there is no way I can change that. (Forgot to mention that I CAN actually encode the URL before hand, that certainly changes things)
I want to encode the URL before it hits my controller and then I want to echo out this URL on the page.
Does codeigniter have any built in methods or what is the .htaccess
rule I need to set to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
稍微修改一下后发现:
你所做的就是将 URL 编码为 base64
base64_encode($uri)
;如果您在 URI 消息中收到不允许的字符,请转至
application/config/config.php
并设置$config['permissed_uri_chars']
以接受有问题的字符。就我而言,我需要为我的参数启用=
。最终的配置参数如下所示:
在控制器端,我只需一个
echo base64_decode($url);
这样我就可以将几乎任何字符串传递到 URL 段中并且它可以工作。
URL 段将使用一系列数字和字母进行编码,这些数字和字母会转换为其中编码有 URI 的字符串。
:)
( PS 光明节快乐 & 嫁给 xMAS)
感谢这个问题的帮助
代码点火器: : 发送 url 作为参数?
hacked around a little and figured it out:
What you do is encode the URL as base64
base64_encode($uri)
;and if you get a disallowed characters in URI message , go to
application/config/config.php
and set$config['permitted_uri_chars']
to accept the problem characters. In my case I needed to enable=
to my parameter.Final config param looks like this:
on the controller end I simply have a
echo base64_decode($url);
This way I can pass pretty much any string into the URL segment and it works.
The URL segment will be encoded with a series of numbers and letters translating to the string that has a URI encoded within it.
:)
( P.S. Happy Hanukkah & Marry xMAS)
Thanks to this question for assistance
code igniter :: send url as param?