开发者

php simplexml_load_file() with password protected url

开发者 https://www.devze.com 2023-01-01 18:19 出处:网络
Simple question for the one who 开发者_JAVA技巧knows the answer... $xml = simplexml_load_file(\"http://url/path/file.xml\");

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号