Find out where a url points to

Find out where a url points to
This PHP source code uses sockets to retrieve the URL that points to, without you having to actually access the URL.
1. <?php
2. // The TinyUrl you want to analyze
3. $TinyUrl = "";
4. // Find out where the parameter starts
5. $ParamStart = stristr($TinyUrl, "");
6. // Extract the parameter out of the URL
7. $Param = substr($ParamStart, 12);
8. // Open a socket to
9. if($UrlSock = fsockopen("", 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:\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 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. ?>
Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

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

Back To Top