Jump to content

Php Url Shortening - Tutorial Scurtare Link-Uri


gaby

Recommended Posts

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.