0

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.

  • http://stackoverflow.com/questions/5849013/setcookie-does-not-set-cookie-in-google-chrome Tried out with once this Procedure. – Dharmendra Aug 30 '16 at 13:49
  • I looked at the topic but what do you mean? I should specify that I am not on localhost and I have no problem with the cookie expiration date. – Mr Cravate Aug 30 '16 at 15:32

1 Answers1

0

A friend of mine found the answer here: What to do with chrome sending extra requests?

Chrome is sending extra requests, apparently for surfing speed purpose. My problem was coming from this particular html tag: <link rel="icon" type="image/png" href=""/> The empty href was the issue. I just deleted the tag, but I guess putting a valid image url works just as well.

Community
  • 1
  • 1