发送带有file_get_contents饼干

php
2022-08-30 11:19:33

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);

如何发送多个饼干?比如#1或#2,还是什么?

#1

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

#2

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

答案 1

#3

Cookie: user=3345; pass=abcd

答案 2

两者都不正确。您可以用以下方式分隔它们:;

Cookie: user=3345; pass=abcd

推荐