php - 通过 CURL 读取 cookie 的最佳方式是什么?
问题描述
我正在通过运行测试 CURL 读取随机页面上的 cookie 的能力:
$ch = curl_init('https://www.forocoches.com/foro/showthread.php?t=7903192');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}
我希望得到类似的东西:
"__cfduid", "_fbp", "_ga", "_gid", "bblastactivity", "bblastvisit", "freewheel-detected-bandwidth", "GED_PLAYLIST_ACTIVITY", "sas_euconsent_v2"
但我只得到:
"bblastactivity", "bblastvisit", "__cfduid"
那是因为其他人需要更长的时间才能被丢弃吗?我能做些什么来抓住他们吗?
解决方案
推荐阅读
- node.js - Error [CredentialsError]: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
- docker - 无法连接到服务器:主机名可能不为空
- excel - 在 Excel 中使用文本导入向导复制矩阵
- html - TinyMCE and Drag Conflict Issues
- javascript - Vue.js 组件不会通过其数据更改其 HTML 输出
- html - Changing div based on color behind it
- python - 为什么 Python 元组中的整数比较会给出不同的答案?
- ruby - Rails GraphQL: Parameter of resolver-methods - Meaning of the semicolon-suffix?
- apache-zookeeper - Zookeeper 没有这样的文件或目录
- compiler-errors - 在jetson arm64 nvidia-docker env中编译opencv-python的自定义版本时出错