tags:

views:

89

answers:

2

I have a xml-file on subdomain a, and a php script on subdomain b. I want to read, and use, the data from the XML file, through PHP.

Here's the catch. The file is secured using HTTP Authentication.

How do I make PHP log-in, and read the contents of the file?

+3  A: 

The url wrappers support URLs of the form http://USER:[email protected]/foo/bar so you could simply use file_get_contents.

Alternatively, you could fetch it with cURL, either shelling out to use a curl command line, or using the curl extension. Failing that, you could hand code the request using fsockopen etc. Basic authentication is called Basic for a reason - it's trivially easy to implement: here's one user-submitted example in the manual.

Paul Dixon
A: 

Unless you need the advanced versions of cURL (which is less necessary these days IMO) you can just start the filename with 'http://user:[email protected]' whereever you read the XML file and it should work pretty transparently. It will use a blocking connection, so your script will pause while it waits for a response.

$xdocument = simplexml_load_file('http://user:[email protected]/thexmlfile.xml');
thomasrutter
for some reason it doesn't seem to be loading the document,while the previously suggested 'file_get_contents' doesthx anyways :)
Jasper