6

Simple question for the one who knows the answer...

$xml = simplexml_load_file("http://url/path/file.xml");

This url is .htaccess protected, how can I pass the login/password as arguments to the function?

hakre
  • 193,403
  • 52
  • 435
  • 836
Pierre
  • 4,976
  • 12
  • 54
  • 76

3 Answers3

10
$xml = simplexml_load_file("http://username:password@url/path/file.xml");

Try that :)

Phliplip
  • 3,582
  • 2
  • 25
  • 42
1

file_get_contents or curl will allow you to set the user authentication using http://username:password@url/path/file.xml.

Take the string data and pass into simplexml_load_string.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
MANCHUCK
  • 2,424
  • 1
  • 16
  • 22
1

allow_url_fopen and allow_url_include must be turned on in php.ini (or propriertary .htaccess) before you are able to do this. It was most likely not set up on your server and must be changed by hand.

An example .htaccess setup with these values would be:

php_value allow_url_fopen 1
php_value allow_url_include 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
  • Found this same answer here: http://forums.phpfreaks.com/index.php?topic=295326.msg1398390#msg1398390. Unfortunately it doesnt work for me. – Zach Lysobey Jul 01 '12 at 20:04