是否可以对包含 url 编码的 url 进行 urlencode?
我有一个网站,使用 Facebook、Twitter、美味分享链接。它们包含您希望共享的网站的 url 编码 url。问题是我想通过 php 重定向页面发送 facebook/twitter/delicious url。
在编码的 url 中对 url 进行编码是否有效?会有副作用吗?
为了简化我的问题:
www.website.com/redirect.php?url=" URLENCODED (http://www.facbook.com/sharer.php?t='URLENCODED(title)'&u='URLENCODED(http://www.hotel.com)')
I have a website that uses the facebook, twitter, delicious share links. They contain a a url encoded url of the website that you wish to share. The problem is I then want to send the facebook/twitter/delicious url through a php redirect page.
Will it work to encode a url within an encoded url? Will there be side effects?
To simplify my question:
www.website.com/redirect.php?url=" URLENCODED (http://www.facbook.com/sharer.php?t='URLENCODED(title)'&u='URLENCODED(http://www.hotel.com)')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以使用百分比编码对字符串进行多次编码,并通过解码相同次数来获取原始值:
这里
$str
的值被编码三次,然后解码三次。重复编码和解码的输出与$str
的值相同。所以试试这个:
You can encode a string multiple times with the percent encoding and get the original value by decoding it the same amount of times:
Here the value of
$str
is encoded three times and then decoded three times. The output of that repeated encoding and decoding is identical to the value of$str
.So try this:
您应该能够根据需要对 URL 进行多次递归编码。如果你重复编码像 / 这样的字符,你会得到:
等等。
You should be able to recursively encode the URL as many times as you want. If you encode a character like / repeatedly you will get:
etc.
加第二层URLEncoding就可以了。 URLEncoding 的想法是防止服务器错误解释文本字符串中可能存在的任何特殊字符。然而,接收脚本必须期望有一个额外的 urlencode() 层,并采取相应的行动。
或者,如果您知道该字符串已经过 urlencoded,您难道不能简单地按原样传递它吗?不需要进一步的 urlencoding。
It's all right to add a second layer of URLEncoding. The idea of URLEncoding is to prevent the server from misinterpreting any special characters that may be present in a text string. However, the receiving script must expect an extra layer of urlencode(), and act accordingly.
Or if you know the string has been urlencoded, couldn't you simply pass it along as-is? No further urlencoding is necessary.
或者只是对标题和 URL 进行 urldecode,然后对整个字符串进行 urlencode。
Or just urldecode the title and URL, then urlencode the whole string.
正如前面提到的,您可以根据需要对 url 进行编码,但您应该知道对 url 数据进行编码的次数越多,长度就会增加得越多,长度可能会增加两倍。如果太长,用户会感到厌烦。某些浏览器上的 url 长度也可能有限制。
此外,在服务器端也会有数据编码和解码的开销。
简而言之,您应该在多次编码/解码之前确定您需要它。
As mentioned earlier you can encode urls as much as you like but you should know the more times you encode url data the more it'll increase in length may be up two twice in length. which will be annoying for users if it is too long. also there may be a limitation on url length on some browsers.
Also on the server side there will be an overhead encoding and decoding the data.
In short you should really be sure you need it before encoding/decoding multiple times.