<?
class SlistenerPHP{
var $scip = "http://109.70.146.200"; // radio server
var $scport = 8000; // port
var $scpass = "********"; // radio server admin password
var $returnArr = array("SlistenerPHP v.0.8.1",array());
var $dataArr = array("CURRENTLISTENERS","PEAKLISTENERS","MAXLISTENERS","AVERAGETIME","SERVERURL ","SERVERTITLE",
"SONGTITLE","IRC","WEBHITS","STREAMHITS","VERSION","SONGHISTORY");
function GetData(){
$scfp = @fsockopen($this->scip, $this->scport, &$errno, &$errstr, 10);
if(!$scfp) {
echo $errstr;
}else{
fputs($scfp,"GET /admin.cgi?pass=$this->scpass&mode=viewxml HTTP/1.0\\r\
User-Agent: SHOUTcast Song Status (Mozilla Compatible)\\r\
\\r\
");
while(!feof($scfp)) {
$page .= fgets($scfp, 1000);
}
$xmlData = substr($page,42);
//echo $xmlData;
for($e=0;$e<count($this->dataArr);$e++){
if($this->dataArr[$e]!="SONGHISTORY"){
$this->returnArr[1][$this->dataArr[$e]] = $this->GetElementByName($xmlData, "<".$this->dataArr[$e].">", "</".$this->dataArr[$e].">");
}else{
$this->returnArr[1][$this->dataArr[$e]] = $this->GetSongHistory($this->GetElementByName($xmlData, "<".$this->dataArr[$e].">", "</".$this->dataArr[$e].">"));
}
}
fclose($scfp);
}
}
function GetSongHistory($xml){
$dataArr = explode("<SONG>",$xml);
$returnArr = array();
for($e=0;$e<count($dataArr);$e++){
$returnArr[$e] = $this->GetElementByName($dataArr[$e],"<TITLE>","</TITLE>");
}
return $returnArr;
}
function GetElementByName ($xml, $start, $end) {
$startpos = strpos($xml, $start);
if ($startpos === false) {
return false;
}
$endpos = strpos($xml, $end);
$endpos = $endpos+strlen($end);
$endpos = $endpos-$startpos;
$endpos = $endpos - strlen($end);
$tag = substr ($xml, $startpos, $endpos);
$tag = substr ($tag, strlen($start));
return $tag;
}
}
$listen = new SlistenerPHP();
$listen->GetData();
echo "<h2>".$listen->returnArr[0]."</h2><i>".$listen->scip.":".$listen->scport."</i><hr>";
while(list($key,$val)=each($listen->returnArr[1])){
echo "<b>".$key."</b> : ";
if($key=="SONGHISTORY"){
echo "<blockquote><blockquote><blockquote>";
for($e=1;$e<count($val);$e++){
echo $e.". ".$val[$e]."<br>";
}
echo "</blockquote></blockquote></blockquote><br>";
}else{
if($key=="AVERAGETIME"){
echo date("H:i:s",$val)."<br>";
}else{
echo $val."<br>";
}
}
}
?>
How can I work around this?
This is for shoutcast stats, but my station only works if you put http:// at the start of it.