Jump to content

Php Url Shortening - Tutorial Scurtare Link-Uri


Recommended Posts

Posted

In momentul in care doriti sa va scurtati dimensiunea unuia sau mai multor link-uri, puteti apela la unul dintre servicile: http://bit.ly / http://tinyurl.com / http://1l2.us / etc.

urlshortening.jpg

Pentru automatizarea unui proces de scurtare a link-urilor pentru site-ul dumneavoastra serviciile mentionate mai sus va pun la dispozitie cate o cheie API (Application Programming Interface), ce poate fi folosita pentru query-uri precum cele ce urmeaza:

  • Exemplu de query cu variabile de tip _GET (Bit.ly):
    <?php
    function make_bitly_url($url, $login, $appkey, $format = 'xml', $version = '2.0.1') {
    $bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format;
    $response = file_get_contents($bitly);
    if(strtolower($format) == 'json') {
    $json = @json_decode($response,true);
    return $json['results'][$url]['shortUrl'];
    } else { // xml
    $xml = simplexml_load_string($response);
    return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
    }
    }
    ?>[/php]



  • Exemplu de query cu variabile de tip [b]_POST[/b] ([color="#0000FF"]1L.us[/color]):
    [php]<?php
    function make_1l2_url($url, $key){
    $file = 'http://1l2.us/Robot.php';

    // Set the query
    $q = 'k='.$key.'&u='.urlencode(stripslashes($url));

    // Perform the CURL REQUEST
    $ch = curl_init($file);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $q);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    // Get the response
    $data = curl_exec($ch);

    // Return the response
    return $data;
    }
    ?>


Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.