Find out where a TinyUrl.com url points to

Find out where a TinyUrl.com url points to
This PHP source code uses sockets to retrieve the URL that TinyUrl.com points to, without you having to actually access the URL.
1. <?php
2. // The TinyUrl you want to analyze
3. $TinyUrl = "http://tinyurl.com/q8zo4";
4. // Find out where the parameter starts
5. $ParamStart = stristr($TinyUrl, "tinyurl.com/");
6. // Extract the parameter out of the URL
7. $Param = substr($ParamStart, 12);
8. // Open a socket to tinyurl.com
9. if($UrlSock = fsockopen("tinyurl.com", 80, $ErrNum, $ErrStr, 30))
10. {
11.        // If successfully open
12.        if ($UrlSock)
13.        {
14.                // Pass the headers
15.                fputs($UrlSock, "HEAD /".$Param." HTTP/1.0\r\nHost: tinyurl.com\r\n\r\n");
16.                // Read the response
17.                while (!feof($UrlSock))
18.                {
19.                        $Headers .= fgets ($UrlSock, 128);
20.                }
21.                // Close the socket
22.                fclose ($UrlSock);
23.        }
24.        // Extract the location that tinyurl.com sends us to
25.        $Arr = explode("Location:", $Headers);
26.        $SubArr = explode("\n", trim($Arr[1]));
27.        // Show the location
28.        echo "The URL behind is: ".trim($SubArr[0]);
29. }
30. ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top