yourls

Yourls - Post Custom Short Url by Api


I could not find how I can send a Custom created URL to Yourls. Normally Yourls gives random generated URL back but I want to speicific URL as response.

Yourls normally return

http://test.it/8sj39

I want to have it. I added the variable $articlenumber but do not know how to send it

http://test.it/test1
http://test.it/doit

My Code is implented inside the dynamic Pages. Shortning will be generated automatically.

$shorturl = 'http://' . $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];
$signature = "12345678";
$siteurl = "http://test.it";
$articlenumber = $Artikel->cArtNr;

// Phases url
$yourlsinput = "".$siteurl."/yourls-api.php?action=shorturl&url=".$shorturl."&signature=".$signature."" ;

// Open phased url
$fh = fopen($yourlsinput, 'r') or die("can't open file");
//$yourlsoutput = fread($fh,filesize($yourlsinput));
$yourlsoutput = fread($fh,1024);
fclose($fh);

// Converts xml to php array
$xml = simplexml_load_string($yourlsoutput);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

Solution

  • You are missing the keyword, you will want to pass the $articlenumber as keyword parameter to curl to make it generate the link with that keyword.