Adfly URL Shortener PHP API

Now days, Adfly is one of the most popular url shortener service on the web. The best thing of this service is that you can earn money through this service and it is the main reason of it's popularity. Nowadays it is providing simple api to made this service more easy.

In this post you will show how we can make short url using Adfly api and PHP.


Step 1 - Get Your Adfly API Key & User ID

To use Adfly API at first you need to get your API key and your user id. If you are a Adfly member you can get these by following way..

Go to http://adf.ly/publisher/tools#tools-api

Here you will fond a link something like this..

http://api.adf.ly/api.php?key=7abccd03cc3005835dc61dd956b583ca&uid=111111&advert_type=int&domain=adf.ly&url=http://somewebsite.com

Here 7abccd03cc3005835dc61dd956b583ca is your API key and 111111 is your user id.

Step 2 - Adfly PHP Function

/**
 * Adfly Url Shortener PHP API
 * 
 * @param string $url http://www.google.com
 * @param string $key 7abccd03cc3005835cc61dd956b583ca
 * @param int $uid 1234
 * 
 * @param string $advert_type (optional) int || banner
 * @param string $domain (optional) adf.ly || q.gs
 */
function adfly($url, $key, $uid, $domain = 'adf.ly', $advert_type = 'int')
{
  // base api url
  $api = 'http://api.adf.ly/api.php?';

  // api queries
  $query = array(
    'key' => $key,
    'uid' => $uid,
    'advert_type' => $advert_type,
    'domain' => $domain,
    'url' => $url
  );

  // full api url with query string
  $api = $api . http_build_query($query);
  // get data
  if ($data = file_get_contents($api))
    return $data;
}

Usage:

// Your api key
$apiKey = '7abccd03cc3005835dc61dd956b583ca';
// Your user id
$uId = 111111;

echo adfly('http://w3bees.com', $apiKey, $uId);

Output:

http://adf.ly/Wtvpt

60 comments:

  1. Replies
    1. ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵
      ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵
      ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵ ͇͇̳̳̳̳̳͇̿̿͏҉͙͖͕͔͓͎͇͉͈͍͚͙͙͖҇͗͒͑͐̈́̓͊͋͌͛͗ͫͮͯ͘͘͟͜͡͠͞͝ͅʹ͵

      Delete
  2. Hi there, do you think is possible to integrate it with a download manager script ?

    ReplyDelete
  3. Its very good. Thanks for sharing this.



    ReplyDelete
  4. Thanks for sharing this post to us. This is really informative about computers.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. ok. On my server allow_url_fopen is disabled. Maybe have another alternative with curl?

    ReplyDelete
  8. How can i add a text field and a submit button with this?

    This would allow me to enter links in a text box, click submit and adfly links will be returned.

    ReplyDelete
  9. Thanks for sharing informative article!!! Your article helped me a lot to understand the importance of PHP Training Center in Chennai to secure lucrative job in web design and development industry.

    ReplyDelete
  10. Thanks for that.You sharing very helpful information..It's really understand for PHP Developer..

    Informatica Training in Chennai | Oracle DBA Training in Chennai

    ReplyDelete
  11. Hello, Can anyone help me about the career path and chances in choosing PHP? I have planned to do PHP Training in Chennai. Someone suggest where to join for the best PHP Training in Chennai where I could also get placement services?

    ReplyDelete
  12. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    Regards,
    Python Training in Chennai|Python Training|Python Training Institutes in Chennai

    ReplyDelete
  13. Very nice piece of article which can help many developers, thank you for sharing your knowledge with us. Keep sharing.
    PHP training in Chennai||PHP course in Chennai ||PHP training institute in Chennai

    ReplyDelete
  14. The main thing which i like about web designing is that itneeds creativity and we need to work differently acccording to our clients need this needs a creativity and innovation.
    web designing course in chennai|web designing training in chennai|web designing courses in chennai

    ReplyDelete
  15. After the website s completed it is very impoprtant to market it. Be it a brand or a website, if you want to reach a large audiece then effective marketive should done and this can be achieved by SEO.
    Seo training in chennai|Seo training|Seo courses in chennai|Seo training chennai

    ReplyDelete
  16. As the world is constantly getting advanced digitally for every brand or a company it is very important to mark their presence online. not only to mark their presence they also have to be very active on the web so that they can have a conversation with their clients/customers and solve their problems or improve their service.
    Digital Marketing Training in Chennai|Digital Marketing Course in Chennai|Digital Marketing Chennai

    ReplyDelete
  17. Hi author I actually teach web designing, and after I read this article I was able to clarify a doubt and this helped me understanding a certain concept better and so I could teach my students well. Thank you.
    web designing course in chennai|web designing training in chennai

    ReplyDelete
  18. Hi, actually I'am new to angularJs and infact I'am learning angularjs with online training. I'am having doubt, if you could solve the doubt for me that would be very helpful. The doubt is, how can I reset a “$timeout”, and disable a “$watch()”?
    Regards,
    angularjs training in Chennai|angularjs course in Chennai|Fita Chennai reviews

    ReplyDelete
  19. If you are willing to develop a website but you dont know web development or coding then relax wordpress CMS platform is just for you. Where you can create website all by yourself.
    wordpress training in chennai | Wordpress course in chennai | FITA Academy reviews

    ReplyDelete
  20. Best Java Training Institute In ChennaiThis information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic..

    ReplyDelete
  21. Quite informative post on AdFly URL shortener!!
    PHP Training in Chennai

    ReplyDelete
  22. very informative blog. Helps to gain knowledge about new concepts and techniques. Thanks for posting information in this blog
    informatica Training in Chennai

    ReplyDelete
  23. what a great post with lots of apps thanks for helpful sharing..Buzz Applications

    ReplyDelete
  24. In India thenumber of smartphone users have been on a rise. Among them also the people using android is way to high. Being an android developer would be the dorrect career choice.
    Android training in Chennai | Android course in Chennai | Android training institute in Chennai

    ReplyDelete
  25. nice sharing..
    Best SEO training in hyderabad all modules are clearly solved and practice with guide.seo training in hyderabadAnd clearly getting knowledge of seo.

    ReplyDelete
  26. Thanks for sharing this informative content that guided me to know the details about the training offered in different technology.
    digital marketing course in chennai | digital marketing training in Chennai

    ReplyDelete
  27. nice! thank you so much! Thank you for sharing. Your blog posts are more interesting and impressive. I think there are many people like and visit it regularly, including me.
    192.168.1.1

    ReplyDelete
  28. Are you looking to make cash from your visitors by popup advertisments?
    In case you do, did you ever use Pop Cash?

    ReplyDelete
  29. Did you know you can create short links with OUO and get dollars from every click on your shortened links.

    ReplyDelete
  30. 100% Job Oriented R Programming Training In Chennai for more Information click to the best msbi training in chennai

    ReplyDelete
  31. 100% Job Oriented R Programming Training In Chennai for more Information click to the best cloud-computing training in chennai

    ReplyDelete
  32. Extremely enlightening substance. Digital marketing is the best to promote our product. We mainly focus on SMO and SEO in digital marketing. The main task is to analyze the keyword and to bring the site at the top position for particular keyword.
    Digital Marketing Training in Chennai | Digital Marketing Chennai | Digital Marketing courses in Chennai

    ReplyDelete
  33. Thanks for sharing this informative articles.
    Keep updating more:)

    Best Spring Training in Chennai

    ReplyDelete
  34. 100% job oriented training & placements in chennai.
    Best software training in chennai.
    Best software training in chennai

    ReplyDelete
  35. Thanks for posting this useful content, Good to know about new things here, Let me share this,
    AngularJS Training in Chennai | AngularJS Training | Best AngularJS Training Institute in Chennai

    ReplyDelete
  36. This comment has been removed by the author.

    ReplyDelete
  37. “Bác sĩ.” Tả Phán Tình nuốt nước miếng, ngẩng đầu nhìn bác sĩ kiên quyết mở miệng: “Tôi muốn bác sĩ giúp tôi bỏ đứa bé này.”
    “Cái gì?” Bác sĩ sửng sốt một chút, cô sở dĩ ấn tượng sâu sắc với Tả Phán Tình là bởi vì vẻ lo lắng, sầu lo trong mắt Tả Phán Tình hôm Tiếng anh cho người đi làm
    Tiếng anh cấp tốc
    Luyện thi toeic tại hà nội
    Tiếng anh cho người lớn tuổi
    Tiếng anh cho người mới bắt đầu
    Học tiếng anh tại hà nội
    dạy tiếng anh cho doanh nghiệpđó, lúc đó cô lo lắng sợ đứa bé có chuyện. Vì sao bây giờ lại muốn bỏ đứa bé?
    “Cô ơi, cô nói gì vậy?”
    “Tôi nói, cô giúp tôi bỏ đứa bé này đi.”

    ReplyDelete
  38. Get daily ideas and methods for making THOUSANDS OF DOLLARS per day ONLINE for FREE.
    JOIN NOW

    ReplyDelete
  39. Thanks for posting this useful content, Good to know about new things here, Let me share this,
    AngularJS Training in Chennai | AngularJS Training | Best AngularJS Training Institute in Chennai

    ReplyDelete

Go to top