I have an issue with the value of a cookie, this issue happens only whenusing Chrome but not on Firefox or IE.
I have the following code, which runs every time the user logs in:
function randomUserKey($length)
{
$random = openssl_random_pseudo_bytes($length);
$key = bin2hex($random);
return $key;
}
/*SET COOKIE*/
$UserKey= randomUserKey(32);
$expiration= time() + 365*24*3600;
setcookie('CookieID', $UserKey, $expiration, NULL, NULL);
//testing the value of $UserKey in the console
echo'<script type="text/javascript">console.log("'.$UserKey.'");</script>';
/************/
Now, if I compare the value of $UserKey
in the console to the value of the cookie in the Response Headers it as a value of X in FF and IE. Which is what I want.
But on Chrome, the value in the console is X, and the value in the Response Header is Y. And if I look at the Request Header, the cookie as the correct value: X.
On FF or IE, the cookie in the Request Header as the value of the previously created cookie (previous connexion of the user). This is the correct behaviour, the one I am expecting. User comes with a cookie > I check the value > It's verified > user is logged in and gets a new cookie.
So I definitely have a problem on Chrome, but I can't figure out where it is coming from.
Thank you for any help you can give, I can provide more code if needed.