1

我的意思是,我想打开另一个网站上的图像文件,但是他们有某种服务器端脚本,仅在浏览器上设置了某个 cookie 的情况下才提供图像。

我可以fopen在 cookie 标头中发送呼叫吗?

4

1 回答 1

7

是的,您可以通过配置 HTTP 流上下文来控制 HTTP 请求,包括添加 cookie。

从手册中查看这个例子:http: //php.net/stream-context-create

$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

/* Sends an http request to www.example.com
   with additional headers shown above */
$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);

有关所有 HTTP 上下文选项,另请参见http://php.net/manual/en/context.http.php

于 2013-11-11T04:22:36.440 回答