php - 使用 file_get_contents 发送 cookie

标签 php

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"

最佳答案

#3

Cookie: user=3345; pass=abcd

关于php - 使用 file_get_contents 发送 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3431160/

相关文章:

php - Alamofire swift : upload more than 10mb file?

javascript - 在同一个 (.js) 文件和另一个 PHP 文件中调用 Jquery 函数?

Nginx + php-fpm : 504 timeout error - upstream timed out (110: Connection timed out)

javascript - 如何将 Knockout.JS 与服务器已在 DOM 中呈现的数据同步?

php - Apache 配置 ssl

php - 使用 javascript 验证输入数组

javascript - 如何从对象数组中提取 jqCharts 的数据?

php - 将在本地工作但不在域中工作的当前日期添加小时数

php - Unicode字符插入数据库后变成问号

php - Ubuntu PHP fatal error : Call to undefined function mysqli_connect() in. 。调用PHP脚本时