Wie kann ich alle Cookies anzeigen die mir bei einem Curl Request gesendet wurden?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true); // Include headers in the output
$response = curl_exec($ch);
curl_close($ch);
list($headers, $body) = explode("\r\n\r\n", $response, 2);
$headerLines = explode("\r\n", $headers);
$cookies = array();
foreach ($headerLines as $line) {
if (strpos($line, 'set-ookie:') === 0) {
$cookieLine = trim(substr($line, strlen('set-cookie:')));
$cookieParts = explode(';', $cookieLine);
$cookie = array_shift($cookieParts); // Extract the cookie name and value
list($cookieName, $cookieValue) = explode('=', $cookie, 2);
$cookies[$cookieName] = $cookieValue;
}
}
foreach ($cookies as $name => $value) {
echo "Cookie: $name=$value\n";
}