SHOUTcast XML get with php


SHOUTcast XML get with php

我有一个shoutcast管理员,我需要从中读取xml,它看起来像这个

http://SHOUTCAST-IP:PORT/admin.cgi

我需要登录并从http://SHOUTCAST-IP:PORT/admin.cgi?mode=viewxml并使用php来完成,我已经制作了这个脚本

$fp = fsockopen($server, $port, $errno, $errstr, 30);
      fputs($fp, "GET /admin.cgi?pass=".$password."&mode=viewxml HTTP/1.0'r'nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)'r'n'r'n"); //
      while (!feof($fp)) {
          $content = fgets($fp);
}

但它不起作用,它说Unauthorised。我该怎么修?

您确定可以使用标准$_GET变量在那里提供usernamepassword吗?看起来很糟糕的做法!?

我会使用cURL来实现这一点,它既快捷又简单!

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://SHOUTCAST-IP:PORT/admin.cgi");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
curl_close($ch);

这个怎么样

//*********** YOUR FM ***********//
// Begin Configuration
$scdef  =       "YOUR FM"; 
                                        // ABOVE: Default station name to display when server or stream is down
$scip   =       "127.0.0.1";        // ip or url of shoutcast server (DO NOT ADD HTTP:// don't include the port)
$scport =       "5977";              // port of shoutcast server
$scpass =       "mysecretpassword";              // password to shoutcast server
// End Configuration
//*********** YOUR FM ***********//
$scfp = fsockopen("$scip", $scport, &$errno, &$errstr, 30);
 if(!$scfp) {
  $scsuccs=1;
echo''.$scdef.' is Offline';
 }
if($scsuccs!=1){
 fputs($scfp,"GET /admin.cgi?pass=$scpass&mode=viewxml HTTP/1.0'r'nUser-Agent: SHOUTcast Song Status (Mozilla Compatible)'r'n'r'n");
 while(!feof($scfp)) {
  $page .= fgets($scfp, 1000);
 }
 // REST OF YOUR CODE BELOW HERE!