Geekpedia Programming Tutorials






Reveal The Url Behind A Tinyurl

Using sockets in PHP to reveal the path that a tinyurl.com URL really points to by reading the HEAD data.

On Sunday, July 6th 2008 at 11:33 PM
By Andrei Pociu (View Profile)
-----   (Rated 0 with 0 votes)
Contextual Ads
More PHP Resources
Advertisement
  1. <?php
  2. $TinyUrl = "http://tinyurl.com/58zbz6";
  3. $ParamStart = stristr($TinyUrl, "tinyurl.com/");
  4. $C = substr($ParamStart, 12);
  5. if($FSock = fsockopen("tinyurl.com", 80, $ErrCode, $ErrMsg, 30))
  6. {
  7.         if ($FSock)
  8.         {
  9.                 fputs ($FSock, "HEAD /$C HTTP/1.0\r\nHost: tinyurl.com\r\n\r\n");
  10.                 while (!feof($FSock)) {$Headers .= fgets($FSock, 128);}
  11.                 fclose ($FSock);
  12.         }
  13.         $ArrTmp = explode("Location:", $Headers);
  14.         $Arr = explode("\n", trim($ArrTmp[1]));
  15.         echo trim($Arr[0]);
  16. }
  17. ?>
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
There are no comments.

Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs PHP Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons