首页 > 解决方案 > 通过 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"

那是因为其他人需要更长的时间才能被丢弃吗?我能做些什么来抓住他们吗?

标签: phpcurlphp-curl

解决方案


推荐阅读