【发布时间】:2012-10-10 03:44:42
【问题描述】:
我尝试使用以下代码通过代理使用 file_get_contents() 获取页面的源代码
$aContext = array(
'http' => array(
'proxy' => 'tcp://proxy.ssn.net:8080',
'request_fulluri' => true,
),);
$cxContext = stream_context_create($aContext);
$homepage = file_get_contents('http://www.indiaglitz.com/channels/tamil/reviews.asp', False, $cxContext);
echo $homepage;
这在我通过终端执行 php 文件时有效,但是当我使用 httpd(Apache 2)通过浏览器运行文件时,我没有得到输出。
这适用于安装在 Ubuntu 中的 Apache2,但不适用于安装在 Fedora 17 中的 httpd。
错在哪里??
【问题讨论】:
-
你是在终端中运行还是通过浏览器在同一台服务器上运行? php 设置可以关闭非本地文件的 file_get_contents()。 (顺便说一句,您不应该使用 file_get_contents 从 url 获取文件。)