Advertisement
Guest User

Untitled

a guest
Jul 24th, 2012
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php
  2.  
  3. /** d3B#g */
  4.  
  5. error_reporting(E_ALL ^ E_NOTICE);
  6. ini_set('display_errors', TRUE);
  7.  
  8. set_time_limit(15);
  9.  
  10. /** meh codez is so fast I need to use sleep() to make it look like it's doing something */
  11. # sleep(rand(0,5));
  12.  
  13. $url = $_GET['url'];
  14.  
  15. if ( ! filter_var($url, FILTER_VALIDATE_URL))
  16. {
  17.     exit(1);
  18. }
  19.  
  20. /** dump var */
  21.  
  22. $output = NULL;
  23.  
  24. main($url, $output);
  25.  
  26. echo $output;
  27.  
  28. exit(1);
  29.  
  30. /** main function */
  31.  
  32. function main($url, &$output)
  33. {
  34.    
  35.     $http = new HTTP();
  36.     $response = $http->curl($url);
  37.     $headers = $http->parse_headers($response);
  38.    
  39.     if(isset($headers['location']))
  40.     {
  41.         $output .= sprintf('HTTP: %s, Length: %s, Redirected to: %s ', $headers['http'], $headers['content-length'], $headers['location']);
  42.         main($headers['location'], $output);
  43.         return;
  44.     }
  45.    
  46.     if (empty($response))
  47.     {
  48.         /** (╯°□°)╯︵ ┻━┻ */
  49.         $output = 'HTTP Request Failed.';
  50.         return;
  51.     }
  52.    
  53.     $output .= sprintf('HTTP: %s, Length: %s', $headers['http'], $headers['content-length']);
  54. }
  55.  
  56. /** HTTP mockup class */
  57.  
  58. class HTTP
  59. {
  60.     function curl($url, $headers = array())
  61.     {
  62.         $ch = curl_init($url);
  63.         curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1');
  64.         curl_setopt($ch, CURLOPT_HEADER, TRUE);
  65.         curl_setopt($ch, CURLOPT_NOBODY, TRUE);
  66.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  67.         $data = curl_exec($ch);        
  68.         curl_close($ch);
  69.         return $data;        
  70.     }
  71.  
  72.     function parse_headers($headers)
  73.     {
  74.         $headers = explode("\n", $headers);
  75.         foreach($headers as $i => $header)
  76.         {
  77.             $value = explode(' ', $header);
  78.             $key = $value[0];
  79.             $key = strtolower(trim($key, ':'));
  80.             if(strpos($key, 'http') !== false)
  81.             {
  82.                 $key = 'http';
  83.                            
  84.             }
  85.             array_shift($value);
  86.             $return[$key] = implode(' ', $value);
  87.         }
  88.         return $return;
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement