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. ?>
Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to Geekpedia.com. 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