php - Cookies not read in IE

417

Im having a strange problem.

I have a subdomain where a customer comes in with a specific URL When the customer is recognized I set a cookie and redirect them to the main domain. there I check for this cookie to hide some elements. This is working great in Chrome, Firefox and even Edge on Microsoft, but not in IE11 and chrome on Apple machines.

When I type document.cookie in the IE console, I can see the cookie. I display a cookie found message in the console which I can see in chrome etc. but not in IE. So it looks like IE can't find the cookie, while it is actually there.

Is there someone who can explain this behaviour?

894

Answer

Solution:

I finally found the problem. When checking for the existence of the cookie, at first I used this line of jQuery code.

if (document.cookie.split(';').filter((item) => item.includes('cookiename=')).length) {
console.log('cookie found');
}

I briefly saw an error message in IE that pointed to this line of code.

so, I changed it to the, btw much easier, line

if (document.cookie.indexOf("cookiename=") != -1) {
 console.log('cookie found');
 }

which IE has no problem with.

People are also looking for solutions to the problem: php - My code is inserting data even without showing error

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.