PHP - 通过file_get_contents发送cookie
问题描述:
PHP手册上的示例显示了如何使用流上下文发送cookie。以下是摘录:PHP - 通过file_get_contents发送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"
答
#3
Cookie: user=3345; pass=abcd
答
两者都是不正确的。您将它们与;
分开:
Cookie: user=3345; pass=abcd
另外,请记住,等号前的字符串应该是cookie的等号值应该是下面的名字,什么。有时Cookie会被命名为“logininfo”,并且该值包含“username = 123&password = 123”,因此您的标题看起来像“Cookie:logininfo = username = 123&password = 123” – RugerSR9 2014-07-15 14:28:35