I know that I should encodingURI any URL passed anything else because I read this:
http://www.digitalbart.com/jquery-and-urlencode/
I want to share the current time of the current track that I am listening to. So I installed an excellent capper. And I have some code that combines all the bits and does the following: tracks = 2 & time = 967
Since I don’t want everyone to see my private key, I have a small php file that takes input and adds the following, so it looks like this:
http: //myshorten.example/yourls-api.php? Signature = x & action = shorturl & format = simple & url = http: // urltoshorten? track = 2 & time = 967
So, on the main page, I call jquery $("div.shorturl").load(loadall);
Then it does a bit of CURL, and then the shortener returns a nice short URL.
Like this:
$myurl='http://myshorten.example/yourls-api.php?signature=x&action=shorturl&format=simple&url=' . $theurl;
$ch = curl_init($myurl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
echo 'cURL failed';
exit;
}
echo $data;
Everything is perfect.
In addition, a shortened URL is always in the form http: // urltoshorten? Track = 2 — anything after the ampersand is shortened.
I tried to wrap the entire URL in php URLencode, I wrapped track = 2 & time = 967 in both encodeURI and encodeURIComponent, I tried to wrap it all with one or both. And yet, it breaks, although I can see that the submitted URL looks like track = 1% 26time% 3D5 at the end.
If I paste this or even the “normal” version with an unencrypted URL either into yoururls interface, or send it to yoururls via api, like a regular URL inserted into the browser’s location bar, it works fine again.
, , , URL- , , , CURL, ?
: " " ", ?".
, , URL- ,
var track = $.getUrlVar('track');
var time = $.getUrlVar('time');
var, , * , - , , , , -.
- , .