SHOUTcast XML 使用 php 获取

发布于 2024-12-25 18:25:34 字数 672 浏览 4 评论 0原文

我有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);
}

但它不起作用,它说 未经授权。。我该如何修复它?

I have shoutcast administrator and i need to read xml from that it looks like this

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

And i need to login and get the XML Data from http://SHOUTCAST-IP:PORT/admin.cgi?mode=viewxml and do it with php, i have made this script

$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);
}

But it doesn't work, it says Unauthorised. How can i fix it ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮华 2025-01-01 18:25:34

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

我会使用 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);

Are you sure you can use standard $_GET variables to provide username and password there? Seems quite bad practice!?

I would use cURL to achieve this, it's quick and easy!

$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);
┈┾☆殇 2025-01-01 18:25:34

这个怎么样?

//*********** 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!

What about this?

//*********** 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!
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文