是否可以对包含 url 编码的 url 进行 urlencode?

发布于 2024-08-24 21:29:13 字数 347 浏览 3 评论 0原文

我有一个网站,使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

祁梦 2024-08-31 21:29:13

您可以使用百分比编码对字符串进行多次编码,并通过解码相同次数来获取原始值:

$str = implode(range("\x00", "\xFF"));
var_dump($str === urldecode(urldecode(urldecode(urlencode(urlencode(urlencode($str)))))));

这里 $str 的值被编码三次,然后解码三次。重复编码和解码的输出与$str的值相同。

所以试试这个:

'http://example.com/redirect.php?url='.urlencode('http://www.facbook.com/sharer.php?t='.urlencode('title').'&u='.urlencode('http://www.hotel.com'))

You can encode a string multiple times with the percent encoding and get the original value by decoding it the same amount of times:

$str = implode(range("\x00", "\xFF"));
var_dump($str === urldecode(urldecode(urldecode(urlencode(urlencode(urlencode($str)))))));

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:

'http://example.com/redirect.php?url='.urlencode('http://www.facbook.com/sharer.php?t='.urlencode('title').'&u='.urlencode('http://www.hotel.com'))
请别遗忘我 2024-08-31 21:29:13

您应该能够根据需要对 URL 进行多次递归编码。如果你重复编码像 / 这样的字符,你会得到:

0: /
1: %3F
2: %%3F
3: %%%%3F

等等。

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:

0: /
1: %3F
2: %%3F
3: %%%%3F

etc.

戏剧牡丹亭 2024-08-31 21:29:13

加第二层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.

末骤雨初歇 2024-08-31 21:29:13

或者只是对标题和 URL 进行 urldecode,然后对整个字符串进行 urlencode。

Or just urldecode the title and URL, then urlencode the whole string.

青巷忧颜 2024-08-31 21:29:13

正如前面提到的,您可以根据需要对 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文