<?php
$url = "https://threads.com/"; // change to your target URL

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true); // include headers
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// Execute request
$response = curl_exec($ch);
$info = curl_getinfo($ch);

// Split headers/body
$header_size = $info['header_size'];
$header = substr($response, 0, $header_size);

curl_close($ch);

// Extract *all* Set-Cookie headers
preg_match_all('/^Set-Cookie:\s*([^;]+)(;|$)/mi', $header, $matches);
$cookies = $matches[1] ?? [];

// Display them
if ($cookies) {
    echo "Cookies received:\n";
    foreach ($cookies as $cookie) {
        echo htmlentities($cookie) . "\n";
    }
} else {
    echo "No cookies received.\n";
}
