I set up a YOURLS instance on gho.st but I wanted users to be able to simply input a long url on the main page and get returned a short url. The script takes a post input and using yourls-api.php it phases the xml output into a php array for display to the users. Enjoy!
html form
<h2>URL Shortening Service</h2> <form action="shorturl.php" method="post" name="shorturl" id="shorturl"> Long URL:<br /> <input name="shorturl" type="text" id="from" value="http://"/> <br /> <input name="Submit" type="submit" value="Shorten URL"/> </form>
php code for shorturl.php
<?php
// Inputs
$shorturl = $_POST["shorturl"];
$username = "username";
$password = "password";
$siteurl = "http://yourdomain.tld";
// Phases url
$yourlsinput = "".$siteurl."/yourls-api.php?action=shorturl&url=".$shorturl."&username=".$username."&password=".$password."" ;
// 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);
// Output status
echo "
<html><head><title>Yourls</title></head>" ;
echo "<body><p><b>Status:</b> ".$array['status']."<br>";
echo "<b>Message:</b> ".$array['message']."<br>";
echo "<b>Short url:</b> <a href='".$array['shorturl']."'>".$array['shorturl']."</a></p>";
echo "Return to <a href='/'>home page</a> ? </body></html>";
?>








