【问题标题】:Send cookie with file_get_contents使用 file_get_contents 发送 cookie
【发布时间】:2010-08-07 16:26:30
【问题描述】:

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

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

#1

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

#2

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

【问题讨论】:

    标签: php


    【解决方案1】:

    #3

    Cookie: user=3345; pass=abcd
    

    【讨论】:

    • 另外,请记住,等号之前的字符串应该是 cookie 的名称,等号之后的任何内容都应该是值。有时 cookie 被命名为“logininfo”并且值包含“username=123&password=123”,因此您的标题看起来像“Cookie: logininfo=username=123&password=123”
    【解决方案2】:

    两者都不正确。你用;分隔它们:

    Cookie: user=3345; pass=abcd
    

    【讨论】:

      猜你喜欢
      • 2010-09-23
      • 2012-07-21
      • 2016-01-15
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多