dpxkkhu1812 2011-10-28 21:04
浏览 40
已采纳

文档末尾的额外内容

I have the following PHP code which simply grabs a URL behind HTTP-Basic authentication and re-serves it:

<?PHP
    header("Content-Type: text/xml");

    $username = "username";
    $password = "password";
    $url = "http://s6.voscast.com:7158/admin.cgi?mode=viewxml";

    $context = stream_context_create(array(
        'http' => array (
            'method' => "GET",
            'header' => "Authorization: Basic ".base64_encode($username.":".$password)."
".
                        "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Ubuntu/11.04 Chromium/14.0.835.202 Chrome/14.0.835.202 Safari/535.1"
        )
    ));

    print file_get_contents($url, false, $context);
?>

It works without any issues locally on my Linux Mint 11 machine (v. 5.3.5), but fails on another Linux server of a client which is running 5.2.14:

enter image description here

It seems like it's trying to validate the XML, which is totally unnecessary. Is there a way I can disable this feature or investigate further as to what's going wrong?

When I look at the source of the response, I see the following:

failed to open stream: Connection refused in /home/livshin/public_html/wp-content/uploads/_radio/songinfo.php on line 16

It's working fine locally, but is failing online? How can I further debug this?

  • 写回答

3条回答 默认 最新

  • duan2477 2011-10-28 21:17
    关注

    Try a simple test case to see if you can access any internet website. e.g. <?php echo file_get_contents('http://google.com'); ?> Assuming the code and configuration (username/password) is identical on your local machine and the server, then the problem must be that the server itself is different in some way (e.g. doesn't have internet access).

    Another thing to check would be the PHP configuration on the server. Opening a URL with file_get_contents() can be disabled using the allow_url_fopen setting.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?