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)')
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'))
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With