0

Hi Guys and girls,

I'm doing some work with XML documents and one is stored behind a .htpasswd arrangement. I have a script which requests the xml docs using XMLReader.

So the problem is the secure xml file, does anyone know of a way to access the file without going there and downloading via a browser. I'm hoping there'll be a nifty solution using headers and such.

Any help is much appreciated!

Thanks,

Fost

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Fost
0

You can use file_get_contents(). Just add the user and password to the url in the form:

http://user:pass@example.com/path/to/file.xml

Or you can specify the http header to send in the stream context parameter.

eg:

$context = stream_context_create(array( 
    'http' => array( 
      'method'  => 'GET', 
      'header'  => sprintf("Authorization: Basic %s\r\n", base64_encode($username.':'.$password)), 
      'timeout' => 5, 
    ), 
  )); 
  $xml = file_get_contents('http://example.com/path/to/file.xml', false, $context);

see: http://www.php.net/manual/en/function.stream-context-create.php

Also lookup Basic Authentication in a search engine to get an idea of the headers being sent/received in the http request/response. :)

0

Hey,

Sorry about the late getting back but thanks digital-ether! The stream context worked perfectly!

Had loads of fun playing with this and got the end result I needed.

Great stuff! Thanks again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.