I have a URL which gives an xml output. It requires a username and password which I can access through a browser using the format:
http://username:pa
For XML with basic auth URL try this
$username = 'admin';
$password = 'mypass';
$server = 'myserver.com';
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
)
);
$data = file_get_contents("http://$server/", false, $context);
$xml=simplexml_load_string($data);
if ($xml === false) {
echo "Failed loading XML: ";
foreach(libxml_get_errors() as $error) {
echo "
", $error->message;
}
} else {
print_r($xml);
}