I have a weird warning coming over in my error log for PHP. There is a define statement and the system is reading the cookie just fine…
define('COOKIE_NAME', 'thiscookie');
echo $_COOKIE[COOKIE_NAME];
but for some reason i’m getting the following warning:
[19-Aug-2024 12:30:35 America/New_York] PHP Warning: Undefined array key "thiscookie" in /PATHREMOVED/index.php on line 21
Also tried the alternate way of reading in all the cookies and parsing them; but still gives me the warning even though it’s echoing out the correct cookie value.
$cookies = explode('; ', $_SERVER['HTTP_COOKIE']);
$allCookies = [];
foreach($cookies as $cookie) {
$keyAndValue = explode('=', $cookie);
$allCookies[$keyAndValue[0]] = $keyAndValue[1];
}
echo $allCookies[COOKIE_NAME];
cookie being set with the following:
setcookie(COOKIE_NAME, 'DATA', time()+1324512000, '/', '.MYSITE.com', true, true);
the second option i’m also getting ‘HTTP_COOKIE’, ‘1’, and even replacing the define with the cookie name all generate the warning too.
Is there a reason i’m getting this, maybe something i might have set incorrectly? technically it’s not a big deal but happens on every reload so the error log is getting pretty hefty and i’m missing some real errors that are occurring.
it’s reading just fine and setting as expected in both cases with the define.
using PHP Version 8.3.6
9