$headers = http_get_request_headers();
if (isset($headers['Range'])) {
$exploded_range = explode('=', $headers['Range']);
$limits = explode('-', $exploded_range[1]);
$length = ($limits[1] - $limits[0]) + 1;
$content_range = 'bytes ' . $limits[0] . '-' . $limits[1];
header('HTTP/1.1 206 Partial Content');
header('Accept-Ranges: bytes');
header('Content-Length: ' . $length);
header('Content-Range: ' . $content_range . '/8097152');
header('Content-type: audio/mpeg');
//open the stream, set as resource $fp
$fp = fsockopen("stream.cerritosallstars.com", "80", $errno, $errstr, 30) or die("Unable to connect to server!");
//HTTP commands
$buf = "GET / HTTP/1.0\r\nIcy-MetaData:0\r\n\r\n";
//send HTTP commands in string $buf to stream $fp
fwrite($fp, $buf);
//get next line from stream
$buf = fgets($fp, 1024);
//while pointer is not at EOF
//get next line
$buf = fgets($fp, 1024);
//delete trash (shoutcast headers)
$buf = fgets($fp, 1024);
$buf = fgets($fp, 1024);
$buf = fgets($fp, 1024);
$buf = fgets($fp, 1024);
$buf = fgets($fp, 1024);
$buf = fgets($fp, 1024);
$buf = fgets($fp, 1024);
//break if EOF
if ($buf == "\r\n") {
break;
}
$bytes_sent = 0;
//while pointer is not at EOF, and not too many bytes are sent...
while (!feof($fp) AND ($bytes_sent < $length)) {
//read 1 byte of stream
$buf = fread($fp, 1);
//output byte to iphone;
echo $buf;
$bytes_sent++;
}
fclose($fp);
exit();
}
else {
header('Accept-Ranges: bytes');
header('Content-Length: 8097152');
header('Content-type: audio/mpeg');
echo 'blah';
exit();
}
exit();
}