dongmeng2687 2013-09-10 15:03 采纳率: 0%
浏览 44

通过在PHP 5.4和IIS 8上运行脚本来实现未定义的变量

I have a small question about running a script on windows ( IIS 8 + PHP 5.4 ) I try to make the script below to work.

<?php

class RadInfo {

    private $db;
    private $cfg;
    private $dnas_data;

    function __construct() {
        $this->db = Com_DB::getInstance();
        $this->cfg = new Config();
    }

    function openstats() {

        $ch = curl_init($this->cfg->shoutcasthost . '/admin.cgi?sid=' . $this->cfg->shoutcastsid . '&mode=viewxml');

        curl_setopt($ch, CURLOPT_PORT, $this->cfg->shoutcastport);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->cfg->shoutcastuagent);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_USERPWD, $this->cfg->shoutcastuser . ':' . $this->cfg->shoutcastpasswd);

        $curl = curl_exec($ch);
        curl_close($ch);

        if ($curl) {
            $xml = @simplexml_load_string($curl);
            $dnas_data = array (
                'CURRENTLISTENERS'    => $xml->CURRENTLISTENERS,
                'PEAKLISTENERS'        => $xml->PEAKLISTENERS,
                'MAXLISTENERS'        => $xml->MAXLISTENERS,
                'REPORTEDLISTENERS'    => $xml->REPORTEDLISTENERS,
                'AVERAGETIME'        => $xml->AVERAGETIME,
                'SERVERGENRE'        => $xml->SERVERGENRE,
                'SERVERURL'            => $xml->SERVERURL,
                'SERVERTITLE'        => $xml->SERVERTITLE,
                'SONGTITLE'            => $xml->SONGTITLE,
                'NEXTTITLE'            => $xml->NEXTTITLE,
                'SONGURL'            => $xml->SONGURL,
                'IRC'                => $xml->IRC,
                'ICQ'                => $xml->ICQ,
                'AIM'                => $xml->AIM,
                'STREAMHITS'        => $xml->STREAMHITS,
                'STREAMSTATUS'        => $xml->STREAMSTATUS,
                'BITRATE'            => $xml->BITRATE,
                'CONTENT'            => $xml->CONTENT,
                'VERSION'            => $xml->VERSION,
            );

            if ($dnas_data['STREAMSTATUS'] == 1)
            {
                foreach ($xml->LISTENERS->LISTENER as $listener)
                {
                    $sc_data['LISTENERS'][] = array(
                        'HOSTNAME' =>  $listener->HOSTNAME,
                        'USERAGENT' =>  $listener->USERAGENT,
                        'CONNECTTIME' =>  $listener->CONNECTTIME,
                        'POINTER' =>  $listener->POINTER,
                        'UID' =>  $listener->UID,
                    );
                }

                foreach ($xml->SONGHISTORY->SONG as $song)
                {
                    $sc_data['SONGHISTORY'][] = array(
                        'PLAYEDAT' =>  $song->PLAYEDAT,
                        'TITLE' =>  $song->TITLE,
                    );
                }
            }
        } else {
            $dnas_data = array('ERROR' => 'Could not connect to dnas-server!');
        }


    }


    function LoadServerTitle() {
            return $this->dnas_data['STREAMTITLE'];
    }


}

?>

I have made changes to the script but the output stays on this moment NULL.

I have tried to call the class/function thought:

$comcms->slim->get('/streamtitle', function() use($comcms) {
        $comcms->jsonOutput($comcms->radinfo->LoadServerTitle());
}); 

and

$comcms->slim->get('/streamtitle', function() use($comcms) {
    if ($comcms->radinfo->openstats()) {
        $comcms->jsonOutput($comcms->radinfo->LoadServerTitle());
    }
});

I have tried several options but noting work. I had first problems with cURL but that is solved because PHP fail to load the module.

Now i have problems getting any information. The LoadServerTitle gives a output that says NULL but i cant get it to work properly. The $this->cfg part comes out the database.

Can someone give me a idea to get this script working. I want to thank the people that help me so far.

  • 写回答

1条回答 默认 最新

  • dongqing904999 2013-09-10 15:06
    关注

    You declare $dnas_data in a method, so it won't be accessible outside that method.

    I would suggest you to declare another member variable for storing the data:

    class RadInfo {
    
        private $db;
        private $cfg;
    
        private $dnas_data;
    

    And replace every occurrence of $dnas_data by $this->dnas_data


    I just looked again at your GetServerTitle() method:

    return($this->openstats($dnas_data['SERVERTITLE']));
    

    Do you really want to call openstats() again? Change this to :

    return $this->dnas_data['SERVERTITLE'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?