Hej there,
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:
$resource = fopen( $url, 'r' );
$metadata = stream_get_meta_data( $resource );
$metadata = $metadata['wrapper_data'];
// Looping through the array to find the necessary fields
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.
This still leaves me with a number of URLs I can not check automatically.
Tools like Ask Apache HTTP Headers Tool seem to be more reliable and I was wondering what could be a better way to obtain the redirect information?