How to listen http webradio stream in an https site (Chrome > 80)

How to listen http webradio stream in an https site (Chrome > 80)

Since October 3, 2019 Chrome is gradually rolling out the new security feature that will block mixed content in the websites (info here). So that, if you have a webradio site in https and your streaming is in http, then none will listen to your webradio stream in your site. This is gradually happening at the beginning of 2020. There are multiple solutions, obviously the easiest and the smarter one is to move your streaming to an https connection. 

To do so you can ask your streaming provider to move/modify your server to a secure one. 

But this could take times, could be expansive or impossible (if your streaming provider service do not have this option). A good solution is to proxy the stream using a php script hosted in your website. So suppose you have a website at the address

https://www.myradiowebsite.com

And suppose your stream is at

http://mystreamprovider.mywebradio.com:someport/streamendpoint

Let’s create a file, let’s call it stream.php and let’s wrote in it:

<php?
$filename = "http://mystreamprovider.mywebradio.com:someport/streamendpoint";
header("Content-Type: audio/mpeg");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$filename);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
    echo $data;
    return strlen($data);
});
curl_exec($ch);
curl_close($ch);

With the usage of the curl function in php, basically we are proxying the non-secure connection to the stream with the secure connection of your website. And we’ve also removed the cross-site problem (side effect: we’ve also hidden your streaming provider info, so that, none will know who is hosting your streaming service and can’t know the number of your listeners…). All you have to do now, is to modify in your website, all the references to the original stream so search/replace or configure your website according to this substitution

 

find http://mystreamprovider.mywebradio.com:someport/streamendpoint and replace with https://www.myradiowebsite.com/stream.php

MiroAdmin