- substr: documentation ( source)
- print_r: documentation ( source)
- stream_get_meta_data: documentation ( source)
- strtolower: documentation ( source)
- fopen: documentation ( source)
<?php
$url = 'http://www.example.com/redirecting_page.php';
$fp = fopen($url, 'r');
$meta_data = stream_get_meta_data($fp);
print_r($meta_data);
foreach ($meta_data['wrapper_data'] as $response) {
/* Были ли мы переадресованы? */
if (strtolower(substr($response, 0, 10)) == 'location: ') {
/* Сохранить в $url адрес, куда нас переадресовали */
$url = substr($response, 10);
}
}
?>