开发者

Send cookie with file_get_contents

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

// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
         开发者_StackOverflow中文版     "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?

#1

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

#2

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


#3

Cookie: user=3345; pass=abcd


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

Cookie: user=3345; pass=abcd
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜