Reverse TinyURL, bit.ly, is.gd, and more with PHP and cURL
I’m working on a new project that requires me to take URLs made from url shorteners like tinyurl.com, is.gd, and bit.ly, and reverse them back to their full form.
There are a few online services that do this for you already (even a funny one that takes a small URL and makes it huge), and some of the shortners–like tinyurl–have a few back-door methods to let you reverse their URLs. I needed one I could place in a PHP script–and one that didn’t have the overhead of some I had found across the web.
The PHP code below will take a shortened URL and return you its full form. This has worked on every short-url I’ve tried–but if you find one it stumbles on, please let me know.
Code:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://bit.ly/aKAuf"); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $result = curl_exec($ch); if (preg_match("/Location\:/","$result")) { $url = explode("Location: ",$result); $reversed_url = explode("\r",$url[1]); echo $reversed_url[0]; } else { print_r($result); }
-
Ben
-
http://www.asaami.com Umar
-
Will Knot B. Revealed Snr.
-
Will Knot B. Revealed Snr.
-
Will Knot B. Revealed Snr.
-
Will Knot B. Revealed Snr.
-
Will Knot B. Revealed Snr.
-
Will Knot B. Revealed Snr.
Archives
- May 2012
- April 2012
- March 2012
- January 2012
- December 2011
- November 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2010
- December 2009
- September 2009
- August 2009
- July 2009
- April 2009
- February 2009
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- May 2007
- April 2007
- March 2007
- January 2007
- December 2006
- October 2006
- August 2006



Posted under: