php - 为什么在 CURLOPT_COOKIESSION 设置为默认值时需要 CURLOPT_COOKIEJAR

标签 php cookies curl

我有一个 curl 脚本,用于远程控制(政府)网站的登录。该网站有一个政府范围的登录系统,在各种服务器上使用 5 次重定向。当我设置 CURLOPT_COOKIEJAR 时,我发现登录有效,但我不明白为什么这是必要的。

http://www.php.net/manual/en/function.curl-setopt.php状态:

CURLOPT_COOKIESESSION

TRUE to mark this as a new cookie "session". It will force libcurl to ignore all cookies it is about to load that are "session cookies" from the previous session. By default, libcurl always stores and loads all cookies, independent if they are session cookies or not. Session cookies are cookies without expiry date and they are meant to be alive and existing for this "session" only.

所以看起来默认行为是检索并重新发送所有 cookie?

我会尝试理解为什么我的试错法是成功的

最佳答案

CURL_COOKIEJAR 只是存储 curl 自动解析的 cookie 的文件。另一方面,CURL_COOKIESSION 是一个指令,告诉 curl 它存储的任何被认为是“ session ”cookie 的 cookie 都应该被忽略。因此,要将解析后的 cookie 实际存储在您的系统上,必须将 CURL_COOKIEJAR 设置为该位置。关于存储/加载的声明的实际含义是,默认情况下,无论 cookie 是否为“ session ”cookie,如果它存储在 cookiejar 中,它将随请求一起发送。

关于php - 为什么在 CURLOPT_COOKIESSION 设置为默认值时需要 CURLOPT_COOKIEJAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7960315/

相关文章:

html - 检查 HTML 表单复选框等是否已 POST 设置的正确和最安全的方法是什么?

php - div 中图像到文本的过渡

javascript - 在 react-native 中通过 PUT 方法上传文件

python-3.x - 某些 'utf-8'编解码器无法解码字节

bash - 在 shell 脚本中处理 docker 事件

php - 使用 PECL OS : Ubuntu 在 PHP 5.1.6 上安装 PDO_MYSQL

javascript - 使用 Ajax 的 onclick 事件更新数据库

reactjs - 前后端分离 : Safari not storing cookies from API which is hosted on a separate domain than its Frontend SPA client

java - java中cookie的数量有最大限制吗

ruby-on-rails - 设置cookie。在Rails 5 Controller 集成测试中签名