Use advanced transcoding that streams while transcoding
[noxon-gateway.git] / www / deredirect.php
1 <?php
2 /**
3  * Follow all location redirects of a given URL and redirect to the final URL.
4  *
5  * Noxon iRadio Cube does not like too many redirections
6  * 3 redirects did not work.
7  */
8 $url = $_GET['url'];
9 header('HTTP/1.0 301 Moved Permanently');
10 header('Location: ' . getFinalUrl($url));
11
12 function getFinalUrl($url)
13 {
14     $ctx = stream_context_set_default(
15         array('http' => array('method' => 'HEAD'))
16     );
17     //get_headers follows redirects automatically
18     $headers = get_headers($url, 1);
19     if ($headers !== false && isset($headers['Location'])) {
20         return end($headers['Location']);
21     }
22     return $url;
23 }
24 ?>