I need to view the content of an RSS through PHP, but the problem is that it needs an authentication with username and password, credentials that I have.
How can I print the content of it in my file?
this is what I get when I visit my feed page
I need to view the content of an RSS through PHP, but the problem is that it needs an authentication with username and password, credentials that I have.
How can I print the content of it in my file?
this is what I get when I visit my feed page
cURL may be useful to you here to get the contents of the RSS feed. Pay special attention to the CURLOPT_USERPWD
option:
$process = curl_init($host);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/xml', $additionalHeaders));
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, $payloadName);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
For more information, check out this SO question.
To get the contents of a file with authentication headers (basic auth), you could do something like:
<?php
$url = 'http://www.thelinktorss.com/feed.xml';
$username = 'USER';
$password = 'PASS';
$context = stream_context_create(array('http' => array('header' => "Authorization: Basic " . base64_encode($username . ':' . $password))));
$feed = file_get_contents($url, false, $context);
echo $feed;