【发布时间】:2012-07-07 03:12:10
【问题描述】:
我正在使用 PHP 5.2.17 获取远程页面,HTTP 请求包含一些 cookie 值但 cookie 未传递到目标页面。
$url = 'http://somesite.com/';
$opts = array(
'http' => array
(
'header' => array("Cookie: field1=value1; field2=value2\r\n")
)
);
$context = stream_context_create($opts);
echo file_get_contents($url, false, $context);
你能帮我找出问题吗? 注意:我不能使用 curl。 谢谢。
【问题讨论】:
-
我认为可能是因为某些 PHP 或 Apache 设置,但我不知道在哪里...
-
检查
allow_url_fopen就像我说的那样。如果禁用,您可以使用套接字 i/o 完成任务。查看 here 的示例,在页面中搜索“基于 fsockopen 的 HTTP 请求”。 -
ini_get('allow_url_fopen') 的结果是“1”。
标签: php http-headers