PHP读取受保护的文件 [英] PHP to read secured file
问题描述
我在子域 a 上有一个 xml 文件,在子域 b 上有一个 php 脚本.我想通过 PHP 读取和使用 XML 文件中的数据.
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.
这是问题所在.该文件使用 HTTP 身份验证进行保护.
Here's the catch. The file is secured using HTTP Authentication.
如何登录PHP,读取文件内容?
How do I make PHP log-in, and read the contents of the file?
推荐答案
url 包装器支持 http://USER:PASS@yourdomain.com/foo/bar
形式的 URL,所以你可以简单地使用 file_get_contents.
The url wrappers support URLs of the form http://USER:PASS@yourdomain.com/foo/bar
so you could simply use file_get_contents.
或者,您可以使用 cURL 获取它,要么使用 curl 命令行,要么使用 curl 扩展.如果失败,您可以使用 fsockopen 等手动编码请求.Basic authentication 被称为 Basic原因 - 它非常容易实现:这是手册中用户提交的一个示例.
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.
这篇关于PHP读取受保护的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!