我有shoutcast管理员,我需要读取它看起来像这样的
http://SHOUTCAST-IP:PORT/admin.cgi
我需要登录并从http://SHOUTCAST-IP:PORT/admin.cgi?mode=viewxml获取XML数据并使用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
。我该如何解决?
答案 0 :(得分:0)
您确定可以使用标准的$ _GET变量来提供username
和password
吗?看起来很糟糕的做法!?
我会使用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);
答案 1 :(得分:0)
这个怎么样?
//*********** 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!