title: Fetch HTTP response header/redirect status with PHP
body: <p>Hej there,</p>
  
  <p>I am currently working on a PHP-based Tool to monitor a rather large number of URLs and their redirect status. I have spent quite some time on finding the best way to fetch the content of the HTTP response headers to extract the current redirect code and location. This is how it's done at the moment:</p>
  
  <pre><code>$resource = fopen( $url, 'r' );
  $metadata = stream_get_meta_data( $resource );
  $metadata = $metadata['wrapper_data'];
  
  // Looping through the array to find the necessary fields
  </code></pre>
  
  <p>This works on 95% of the URLs I'm monitoring. For a few more I have solved it by parsing the actual HTML the website returns before the redirect is executed since it contained something like "This website has been moved here". This does not seem to be a very robust solution, but it helped in a few cases.</p>
  
  <p>This still leaves me with a number of URLs I can not check automatically. </p>
  
  <p>Tools like <a href="http://www.askapache.com/online-tools/http-headers-tool/" rel="nofollow noreferrer">Ask Apache HTTP Headers Tool</a> seem to be more reliable and I was wondering what could be a better way to obtain the redirect information?</p>