PHP - 使用 file_get_contents 发送 cookie

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3431160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:44:00  来源:igfitidea点击:

PHP - Send cookie with file_get_contents

php

提问by Majid Fouladpour

The example on PHP manual shows how you can use stream contexts to send a cookie. Here is the excerpt:

PHP 手册上的示例展示了如何使用流上下文发送 cookie。这是摘录:

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

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('http://www.example.com/', false, $context);

How do you send more than one cookie? Like #1 or #2, or what?

如何发送多个 cookie?像#1 或#2,还是什么?

#1

#1

"Cookie: user=3345&pass=abcd\r\n"

#2

#2

"Cookie: user=3345\r\n" . 
"Cookie: pass=abcd\r\n"

回答by mvds

#3

#3

Cookie: user=3345; pass=abcd

回答by NikiC

Both aren't correct. You separate them with ;:

两者都不正确。你把它们分开;

Cookie: user=3345; pass=abcd