Hi there I am making a PHP url shortener using about 4-5 APIs from different websites (to.ly, sn.im, goo.gl, is.dg) and I need to combine them into one PHP script... and also the form lets the user pick which url shortener they want.
to.ly:
<?php
function CompressURL($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://to.ly/api.php?longurl=".urlencode($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$shorturl = curl_exec ($ch);
curl_close ($ch);
return $shorturl;
}
echo CompressURL($_POST[url]); // Test
?>
sn.im:
<?php
// REQUIRED FIELDS
$sniplink = $_POST[url]; // THE URL TO BE SNIPPED
$snipuser = 'alexpja'; // YOUR USER ID REQUIRED
$snipapi = ''; // FIND IN YOUR "SETTINGS" PAGE
// OPTIONAL FIELDS
$snipnick = ''; // MEANINGFUL NICKNAME FOR SNIPURL
$sniptitle = ''; // TITLE IF ANY
$snippk = ''; // PRIVATE KEY IF ANY
$snipowner = ''; // IF THE SNIP OWNER IS SOMEONE ELSE
$snipformat = 'simple'; // DEFAULT RESPONSE IS IN XML, SEND "simple"
// FOR JUST THE SNIPURL
$snipformat_includepk = ""; // SET TO "Y" IF YOU WANT THE PRIVATE KEY
// RETURNED IN THE SNIPURL ALONG WITH THE ALIAS
//----------------------------------
// NO NEED TO EDIT BEYOND THIS POINT
//----------------------------------
$URL = 'http://snipr.com/site/getsnip';
$sniplink = rawurlencode($sniplink);
$snipnick = rawurlencode($snipnick);
$sniptitle = rawurlencode($sniptitle);
// POSTFIELD
$postfield = 'sniplink=' . $sniplink . '&' .
'snipnick=' . $snipnick . '&' .
'snipuser=' . $snipuser . '&' .
'snipapi=' . $snipapi . '&' .
'sniptitle=' . $sniptitle . '&' .
'snipowner=' . $snipowner . '&' .
'snipformat='. $snipformat. '&' .
'snippk=' . $snippk
;
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
// THIS IS MERELY FOR DISPLAY IN A BROWSER
// TO GET THE RESPONSE DATA, JUST USE $data
// echo '<pre>', htmlentities($data), '</pre>';
echo $data;
?>
Help?? and should I name the <option> like... <option name="is.dg">?