DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Resolving A TinyURL To Destination URL

  • submit to reddit
        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 ("", 80, $errno, $errstr, 30))
    if ($fp) {
    fputs ($fp, "HEAD /$num HTTP/1.0\r\nHost:\r\n\r\n");
    while (!feof($fp)) {$headers .= fgets ($fp,128);}
    fclose ($fp);
    echo trim($arr[0]);