Using linkbucks API / posting data using cURL in PHP



  • Register to linkbucks if you don’t have any account there (it’s free and you probably should use email other than gmail and hotmail if you want quick confirmation from linkbucks)
  • Find your username and API password from your profile page: . If your API password is empty, just click “Reset API Password” link to show it.

This is our little PHP function that help us to POST data to certain URL:

//function to POST data using cURL in PHP
function curl_post($url, $data, $ip="", $ref="", $ua="") {
    //initiate cURL
    //set referer only if stated by user
    if ($ref!="") {
        curl_setopt($ch, CURLOPT_REFERER, $ref);
    //set IP interface if needed (for multi-IP server)
    if ($ip!="") {
        curl_setopt($ch, CURLOPT_INTERFACE, $ip);
    //set user agent if stated by user
    if ($ua!="") {
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    return $response;

How to use it to call linkbucks API:

    'user'=>'chmdznr',  //my username
    'apiPassword'=>'d55ae4eaf97b445f',  //my API password
    "originalLink"=>"",  //the URL that need to be shorted
    "adType"=>2,  //paid links
    "contentType"=>1,   //not an adult content
    "domain"=>""  //target domain, a lot of possibility here, the default is: 

//call linkbucks API

$returned_data=curl_post($url, json_encode($data_kirim));

//simple error checking
if (!empty($parsed_data->link)) {
    echo "This is your short URL : ".$parsed_data->link;
} else {
    echo "Something wrong! ".$parsed_data->errorDescription;

The curl_post function is quite generic, you can use it to send data to remote URL using POST method like this:


$returned_data=curl_post($target_url, http_build_query($login_data));

You should notice that the data array need to be converted using http_build_query first (in linkbucks’ case, it doesn’t need to be converted first).
You can also add more advanced feature in the function such as handling the timeout and cookie.

  1. thank you

  2. Great, as usual waiting your review about it 🙂

  3. Thanks, works perfectly!!!

  4. If I want to call this script in bash linux. What should I do?

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>