I’m trying to create a script that will login to an Icecast2 server and grab the metadata for the currently playing tracks. My issue is that the Icecast server is user/pass protected via basic HTTP login.
<?php
$fp = fsockopen("xxxxxxxx.com", 8000, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Icy-MetaData:1\r\n";
$out .= "Host: xxxxxxxx.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$arr = array();
while (!feof($fp)) {
$arr[] = fgets($fp, 128);
}
fclose($fp);
}
echo json_encode(trim(strip_tags($arr[73])));
?>
This is the script that has allowed me to grab metadata before the Icecast server was password protected.
In short, how do I send a user/pass via this script to the Icecast server to login and grab the info successfully? (Uses htpasswd)
Thanks in advanced!
As described on Wikipedia, you need the
Authorization: Basicheader andbase64_encode()username:password.Code to add: