Mudahnya memperpendek URL dengan php, curl pada ADF.LY


Inilah contoh kode PHP :

/*====================== 
Project: URL Shortener using ADF.LY API 
Project URI: http://mirazmac.info 
Description: URL Shortner is a simple script which gives opportunity to your visitors for generating short URL from your site. This SCript uses ADF.LY API. So you will get the money for all the clicks on the generated links.
Project Version: 1.0 
Author: MiraZ Mac(Unsocial) 
Author URI: http://mirazmac.info 
License: Mozilla Public License v3 
======================*/ 
//url auto shortener http://api.adf.ly/api.php?key=AdfLyKey&uid=AdfLyUid&advert_type=int&domain=adf.ly&url=http://somewebsite.com
$api="AdfLyKey";
$uid="AdfLyUid";
//$mydomain="adf.ly";
$mydomain="q.gs";
$link="https://www.facebook.com/alfa.karawang";

//if($_POST['domain'] == ''){header('Location: index.php');}
//else{ 
//$domain=$_POST['domain'];} 

//if($domain == '1'){ 
//$mydomain='adf.ly'; 
//} 
//else{ 
//$mydomain='q.gs'; 
//} 

$ch = curl_init(); //Initializing cuRL :* 
curl_setopt($ch, CURLOPT_URL, 'http://api.adf.ly/api.php?key='.$api.'&uid='.$uid.'&advert_type=int&domain='.$mydomain.'&url='.$link.''); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);   
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16'); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: en-us,en;q=0.7,bn-bn;q=0.3','Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5')); 
$s_link = curl_exec($ch);  
curl_close($ch); //Closing Connection :( 
echo $s_link;

Smoga bermanfaat............
Previous
Next Post »