ari*_*rik 39 php url ini external file-get-contents
我使用以下PHP函数:
file_get_contents('http://example.com');
每当我在某个服务器上执行此操作时,结果为空.当我在其他任何地方进行此操作时,结果就是页面的内容可能是什么.但是,当我在结果为空的服务器上,在本地使用该函数 - 无需访问外部URL(file_get_contents('../simple/internal/path.html');),它确实有效.
现在,我很确定它与某个php.ini配置有关.我不确定的是哪一个.请帮忙.
Ail*_*lyn 41
您正在寻找的设置是allow_url_fopen.
您可以通过两种方式绕过它,而无需更改php.ini,其中一种是使用fsockopen(),另一种是使用cURL.
我推荐使用cURL file_get_contents(),因为它是为此而构建的.
Pab*_*blo 31
作为Aillyn答案的补充,您可以使用类似下面的函数来模拟file_get_contents的行为:
function get_content($URL){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $URL);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
echo get_content('http://example.com');
Run Code Online (Sandbox Code Playgroud)
小智 5
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.your_external_website.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
最适合 http url,但是如何打开 https url 帮助我
| 归档时间: |
|
| 查看次数: |
148139 次 |
| 最近记录: |