36
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"
另外,請記住,等號前的字符串應該是cookie的等號值應該是下面的名字,什麼。有時Cookie會被命名爲「logininfo」,並且該值包含「username = 123&password = 123」,因此您的標題看起來像「Cookie:logininfo = username = 123&password = 123」 – RugerSR9 2014-07-15 14:28:35