0

From JS client side call, I am trying to update Cookie value that originally created from server Side. Now I just noticed that Cookie is created originally with server side will be without . in Domain Name like "www.abc.com"

But once i tried to update cookie by below code with same name from client side js call it creating 2 cookie with same name and different in Domain Name. When we are trying to create cookie from client side its getting created with ".www.abc.com".

I am using below code to update/create with same name :

if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/; domain="+domainurl ;

How can i delete /update that existing cookie without creating duplicate like below.
enter image description here

Its creating Cookie but some different in domain name with or without "." How to resolved this problem, i have refer different links,link2 but could not find the resolution.

In simple work i need to update cookie value from client side same cookie originally created from server side used across java base Spring MVC application.

Thanks in advance for any kind of help and info.

Community
  • 1
  • 1
Gautam
  • 3,707
  • 5
  • 36
  • 57
  • 1
    you may not be able to if server side cookie is `httpOnly` as they are protected. Why can't you do this on server? – charlietfl Oct 04 '16 at 05:17
  • i tried but it i am not able to do the same . any alternate we can use to get rid of creating duplicate just need to update value ? – Gautam Oct 04 '16 at 05:19
  • again...why can't you do it on server? And is it an `httpOnly` cookie? – charlietfl Oct 04 '16 at 05:19
  • 1
    Luckily it isn't that easy to modify cookies especially not `httpOnly` ones (imagine the security implications if it would be!). You really need to fix this on the server side and not on the client. – M. Deinum Oct 04 '16 at 05:46
  • actually i have limited visibility of server side implementation. I mean it cant be accessible to me. – Gautam Oct 04 '16 at 10:58

0 Answers0