通过CURL读取Cookie的最佳方法是什么?

时间:2020-08-15 18:27:20

标签: php curl php-curl

我正在通过运行以下命令来测试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"

是因为其他人需要更长的时间才能掉落吗?我有什么办法可以抓住他们?

0 个答案:

没有答案
相关问题