php simplexml_load_file() with password protected url
Simple question for the one who 开发者_JAVA技巧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?
$xml = simplexml_load_file("http://username:password@url/path/file.xml");
Try that :)
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
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
.
精彩评论