daily pastebin goal
49%
SHARE
TWEET

Solving the URL shortening problem #twitter #tweet

a guest Apr 20th, 2010 404 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. $arg = "http://wp.me/phhhb-ul";
  4.  
  5. if($argv[1] != NULL)
  6.         $arg = $argv[1];
  7.  
  8. while(true) {
  9. $url = split("/",$arg);
  10.  
  11. $ip = gethostbyname($url[2]);
  12. echo "Connect to: ". $url[2] ." (". $ip . ")\r\n";
  13.  
  14. $socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  15. socket_connect($socket, $ip, 80);
  16.  
  17. $the_url = "";
  18.  
  19. for($j = 3; $j < count($url); $j++)
  20.         $the_url = $the_url ."/". $url[$j];
  21.  
  22. $http_req = "HEAD /". $the_url ." HTTP/1.1\r\nHost: ". $url[2] ."\r\n\r\n";
  23.  
  24. socket_write($socket, $http_req, strlen($http_req)+1);
  25.  
  26. $http_res_sz = socket_recv($socket, $http_res, 8196, MSG_WAITALL);
  27.  
  28. $http_res_a = explode("\r\n", $http_res);
  29.  
  30. for( $i = 0; $i < count($http_res_a); $i++) {
  31.         $type = split(" ",$http_res_a[$i]);
  32.         switch($type[0]) {
  33.                 case "HTTP/1.1":
  34.                         if($type[1] > 300 && $type[1] < 400)
  35.                                 echo "Redirection to: ";
  36.                         if($type[1] == 200) {
  37.                                 echo "True URL: $arg\r\n";
  38.                                 exit;
  39.                         }
  40.                         continue;
  41.                 case "Location:":
  42.                         echo $type[1] ."\r\n";
  43.                         $arg = $type[1];
  44.         }
  45. }
  46.  
  47. socket_close($socket);
  48. }
  49.  
  50. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top