0

I am trying to detect if a specific cookie is set: opt-in. I can clearly see it's available in the browser developer tools, however even when listing all cookies available, it's unable to detect this particular cookie and a few others.

enter image description here


JS-COOKIE
My attempt to find the opt-in cookie (I have js-cookie installed).

Cookies.get('opt-in')

Result:

Cookies.get('opt-in')
undefined

Get all cookies. Cookies.get()

_ga: "GA1.3.939192208.1613807258", _gid: "GA1.3.209740233.1613807258", __utma: "196000302.939192208.1613807258.1613807259.1613807259.1", __utmc: "196000302", __utmz: "196000302.1613807259.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)", …}
cookieconsent_status: "allow"
__utma: "196000302.939192208.1613807258.1613807259.1613807259.1"
__utmb: "196000302.4.10.1613807259"
__utmc: "196000302"
__utmt_UA-111246925-1: "1"
__utmz: "196000302.1613807259.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"
__zlcmid: "12kjpCHowceHB1g"
_ga: "GA1.3.939192208.1613807258"
_gat: "1"
_gid: "GA1.3.209740233.1613807258"
__proto__: Object

Raw JS approach:

var allcookies = document.cookie;
console.log(allcookies);

Result:

_ga=GA1.3.168091881.1613808425;
_gid=GA1.3.118848018.1613808425;
__utma=196000302.168091881.1613808425.1613808425.1613808425.1;
__utmc=196000302;
__utmz=196000302.1613808425.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);
__utmt_UA-111246925-1=1;
__zlcmid=12kjpCPhDiUge0l;
__utmb=196000302.2.10.1613808425

Update The comment from Dai made me realise it's because the cookie has HttpOnly and Secure set. So now I am trying to set those to false when the cookie is set, but I think a server setting must be overriding as this isn't working yet:

session_set_cookie_params([
  'httponly' => false,
  'samesite' => false
]);

setcookie('opt-in', 'true', time() + (3600), "/", $_SERVER['HTTP_HOST'], false, false); // 1 hour.
wharfdale
  • 1,148
  • 6
  • 23
  • 53

0 Answers0