文档末尾的额外内容

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?

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.

That error is actually coming from the browser that is interpreting the result it got from the php script.

I'm on Safari on Mac, and I'm seeing the same thing when some error message is produced by my php script.

To see the real text (ie the useful error message) returned by the script, I had to show the source code.

In Safari to show source you need to go to Preferences-Advanced, and check "Show Develop menu...". Then when the error is showing, choose "Show Page Source" from the Develop menu.

Then make sure you choose "Source Code" instead of "DOM tree" from the picker just above the box that shows the text.

Hope that helps!

I had exactly the same problem. The solution was to set the timezone.