Hi All,
I have this authentication code to parse XML from a site.
Got this here - http://stackoverflow.com/questions/3765046/bypass-authenticated-xml-page-to-be-parsed-with-php
My problem is that the same authentication code this not work on a server below. It works on my local env and other servers. Please see sample links below and the code.
Not working - http://beton-sports.com/feeds/test_auth.php - didn't do the authentication, as it says "Authorized required". It gives a SimpleXML error because it parsed an HTML page. (the Authorization required page)
PHP Info - http://beton-sports.com/test.php
Working - http://covers.wikisportsbook.com/feeds/test_auth.php - it did the authentication successfully and parsed the XML. You can see the dump data. (don't mind the file_get_contents error)
PHP Info - http://covers.wikisportsbook.com/test.php
Code:
<?php
$username = 'evercore';
$password = 'somepassword';
$opts = array(
'http' => array(
'method' => 'GET',
'header' => sprintf("Authorization: Basic %s\r\nUser-Agent: Foobar!", base64_encode($username.':'.$password))
)
);
$context = stream_context_create($opts);
libxml_set_streams_context($context);
echo file_get_contents('http://feeds.outgard.net/www.sportsbook.com/trends/203.xml');
$xml = new SimpleXMLElement(
"http://feeds.outgard.net/www.sportsbook.com/trends/203.xml",
null,
true);
var_dump($xml);
?>
Any help and suggestions is greatly appreciated.
Thanks in advance, steamboy