3 * Follow all location redirects of a given URL and redirect to the final URL.
5 * Noxon iRadio Cube does not like too many redirections
6 * 3 redirects did not work.
9 header('HTTP/1.0 301 Moved Permanently');
10 header('Location: ' . getFinalUrl($url));
12 function getFinalUrl($url)
14 $ctx = stream_context_set_default(
15 array('http' => array('method' => 'HEAD'))
17 //get_headers follows redirects automatically
18 $headers = get_headers($url, 1);
19 if ($headers !== false && isset($headers['Location'])) {
20 return end($headers['Location']);