I am trying to check if a cookie is set before loading some scripts, but when I use $_SERVER['HTTP_COOKIE']
or $_COOKIE['cookie_name']
to check for the cookie, it seems to get ignored in Firefox and Safari even though I am not blocking cookies or in a private window or anything like that.
I have tried echoing all of the cookie names with the following:
if (isset($_SERVER['HTTP_COOKIE'])) {
$cookies = explode('; ', $_SERVER['HTTP_COOKIE']);
foreach ($cookies as $cookie ) {
echo '<pre>cookie: ' , $cookie , '</pre>';
}
}
and in Chrome it lists all of the cookies, but in Firefox and Safari there is nothing. I have also tried checking the value of $COOKIE like this:
if(count($_COOKIE) > 0) {
echo "Cookies are enabled.";
} else {
echo "Cookies are disabled.";
}
and in Chrome I get Cookies are enabled, but in Firefox/Safari I get Cookies are disabled.
I am not seeing any errors related to the cookies, but I guess it is worth noting that I am working on a testing server and I do have some warnings about cross-site requests in relation to Google Analytics (e.g. Referrer Policy: Ignoring the less restricted referrer policy “origin-when-cross-origin” for the cross-site request: https://www.googletagmanager.com/gtag/js?id=...
).
Does anyone have any ideas on how to proceed with debugging?
Thanks!