0

I'm having problems using file_get_contents when the URL I'm getting contents from uses X-AUTH authentication. I do have a X-AUTH token but I'm not really sure how to tie it in to file_get_contents. As a result of this I get an error when visiting the page in the browser, part of which is:

Warning: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

I've never had many dealings with file_get_contents nevermind using it with X-AUTH so I'm a bit stuck!

Any help would be much appreciated.

Thanks

DroidShare
  • 30
  • 8
  • I doubt you can use `file_get_contents()` to do this, take a look here instead: http://stackoverflow.com/questions/13187462/sending-auth-in-headers-php-curl – WWW Oct 10 '14 at 19:12

1 Answers1

1

Please read the foloowing blog post:

Using Authentication And file_get_contents()

The blog entry contains a good example on how to achieve this:

$username = 'username';
$password = 'password';

$context = stream_context_create(array(
    'http' => array(
        'header'  => "Authorization: Basic " . base64_encode("$username:$password")
    )
));
$data = file_get_contents($url, false, $context);
meda
  • 45,103
  • 14
  • 92
  • 122