Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Resolving a tinyURL to destination URL

Resolving a tinyURL to its original destination URL in a fastest way.

    < ?php

    // request like this http://<domain>/tinyurl.php?c=<tinyurl>

    $num = $_GET['c'];

    if($fp = fsockopen ("tinyurl.com", 80, $errno, $errstr, 30))
    {
    if ($fp) {
    fputs ($fp, "HEAD /$num HTTP/1.0\r\nHost: tinyurl.com\r\n\r\n");
    while (!feof($fp)) {$headers .= fgets ($fp,128);}
    fclose ($fp);
    }
    $arr1=explode("Location:",$headers);
    $arr=explode("\n",trim($arr1[1]));
    echo trim($arr[0]);
    }
    ?>


http://www.webforth.com/2007/07/resolving-tinyurls-to-the-desination-url
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS