PHP ini file_get_contents 外部网址 [英] PHP ini file_get_contents external url
问题描述
我使用以下 PHP 函数:
I use following PHP function:
file_get_contents('http://example.com');
每当我在某个服务器上执行此操作时,结果都是空的.当我在其他任何地方这样做时,结果就是页面的内容.但是,当我在结果为空的服务器上,在本地使用该函数时 - 无需访问外部 URL (file_get_contents('../simple/internal/path.html');
),它确实有效.
Whenever I do this on a certain server, the result is empty. When I do it anywhere else, the result is whatever the page's content may be. When I however, on the server where the result is empty, use the function locally - without accessing an external URL (file_get_contents('../simple/internal/path.html');
), it does work.
现在,我很确定它与某个 php.ini 配置有关.然而我不确定的是,哪个.请帮忙.
Now, I am pretty sure it has something to do with a certain php.ini configuration. What I am however not sure about is, which one. Please help.
推荐答案
您正在寻找的设置是 allow_url_fopen
.
The setting you are looking for is allow_url_fopen
.
您有两种方法可以在不更改 php.ini 的情况下绕过它,其中一种方法是使用 fsockopen()
,另一种是使用卷曲.
You have two ways of getting around it without changing php.ini, one of them is to use fsockopen()
, and the other is to use cURL.
无论如何,我建议在 file_get_contents()
上使用 cURL,因为它是为此而构建的.
I recommend using cURL over file_get_contents()
anyways, since it was built for this.
这篇关于PHP ini file_get_contents 外部网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!