Reputation: 67
I am trying to shorten a url using the PHP API from bitly. The url I am trying to shorten contains a url in the GET parameters.
The url is similar to
http://www.my.domain.io/Embed.php?k=318353564&p=something&a=someone&d=true&i=http://i.imgur.com/gBlh6Zm.jpg&pop=true&popn=0
When I use a version of the link in which i
has been urlencode()
first, the returned shortened link sends me to is http://www.my.domain.io/Embed.php?k=318353564
the remaining parameters are cut off.
When I use urlencode()
on the entire link after urlencode()
the parameter i
it returns the whole link http://www.my.domain.io/Embed.php?k=318353564&p=something&a=someone&d=true&i=http://i.imgur.com/gBlh6Zm.jpg&pop=true&popn=0
but because the parameter i
is not encoded in the link it just gives me a 403 error.
When I send the link with no encoding at all it returns the link without parameters again. When I send the link with urlencode()
on the entire link it returns the literal version of the link again resulting in a 403 error. So that's 4 different ways of trying to encode the link none of which lead me to the correct link.
Upvotes: 1
Views: 3604
Reputation: 146
You need to use "%26" instead of ampersand (&).
http://www.my.domain.io/Embed.php?k=318353564%26p=something%26a=someone%26d=true%26i=http://i.imgur.com/gBlh6Zm.jpg%26pop=true
When I query bitly API with the following GET parameters:
https://api-ssl.bitly.com/shorten?version=2.0.1&login=<bitly_username>&access_token=<bitly_accesstoken>&format=json&history=1&longUrl=http://www.my.domain.io/Embed.php?k=318353564%26p=something%26a=someone%26d=true%26i=http://i.imgur.com/gBlh6Zm.jpg%26pop=true
I get a link such as http://bit.ly/1n4OuzX, which redirect me to your original URL.
Update: When I change the domain from "www.my.domain.io" to my local web server it sends the parameters to it fine.
Here is a print_r:
Array
(
[k] => 318353564
[p] => something
[a] => someone
[d] => true
[i] => http://i.imgur.com/gBlh6Zm.jpg
[pop] => true
[popn] => 0
)
Upvotes: 4