Aug 18, 2010
I know that I should encodeURI any url passed to anything else, because I read this: [URL] I want to share the current time of the current track I am listening to. So I installed the excellent yoururls shortener. And I have a bit of code that puts all the bits together, and makes the following: track=2&time=967
View 2 Replies
As I don't want everyone seeing my private key, I have a little php file which takes the input, and appends the following, so it looks like this: [URL] So in the main page, I call the jquery of $("div.shorturl").load(loadall); It then does a little bit of CURL and then shortener returns a nice short URL.
Except... the URL which is shortened is always in the form of [URL] - anything after the ampersand is shortened. I have tried wrapping the whole URL in php's URLencode, I've wrapped the track=2&time=967 in both encodeURI and encodeURIComponent, I've evem tried wrapping the whole thing in one or both. And still, the & breaks it, even though I can see the submitted url looks like track=1%26time%3D5 at the end. If I paste this or even the "plain" version with the unencoded url either into the yoururls interface, or submit it to the yoururls via the api as a normal URL pasted into the location bar of the browser, again it works perfectly.
So it's not yoururls at fault, it seems like the url is being encoded properly, the only thing I can think of is CURL possibly? Now at this point you might be thinking "why not replace the & with a * and then convert it back again?". OK, so when the url is expanded, I get the values from
var track = $.getUrlVar('track');
var time = $.getUrlVar('time');
so I COULD lose the time var, then do a bit of finding on where the * is in track and then assume the rest of anything after * is the time, but it's a bit ugly, and more to the point, it's not really the correct way to do things.