PDA

View Full Version : Clearing cookies not functional?



abcdef
24 Aug 2011, 12:51 AM
I am trying to use the cookie clear method:


Ext.util.Cookies.clear(<Cookie Name>);

where the path = / (so I am not passing it), but the cookie remains active in Safari, Chrome and Firefox.

Is this a known issue?

skirtle
24 Aug 2011, 3:00 AM
Could you give a specific example of how the cookie is set and what you're using to clear it? If it's set by a response header could you give an example of that?

abcdef
24 Aug 2011, 10:11 AM
Could you give a specific example of how the cookie is set and what you're using to clear it? If it's set by a response header could you give an example of that?

I am handling setting and clearing of cookies on the client side. So I am setting it as below:


Ext.util.Cookies.set(
name,
value,
Ext.Date.add(new Date(), Ext.Date.DAY, 1000),
'/',
'a.b.com',
true
);

I am trying to clear it as:


Ext.util.Cookies.clear(name);

Any idea?

skirtle
24 Aug 2011, 7:47 PM
Works for me, 4.0.2 and 4.0.5. Here's my test code if you want to give it a try yourself.


Ext.onReady(function() {
Ext.getBody().update('<div></div>');
var state = Ext.getBody().first();
var clear = false;

new Ext.button.Button({
renderTo: Ext.getBody(),
text: 'Click',
handler: function() {
if (clear) {
Ext.util.Cookies.clear('name');
}
else {
Ext.util.Cookies.set('name', 'value', Ext.Date.add(new Date(), Ext.Date.DAY, 1000), '/');
}

clear = !clear;
}
});

setInterval(function() {
state.update('Cookie value: ' + Ext.util.Cookies.get('name'));
}, 100);
});

abcdef
24 Aug 2011, 11:26 PM
Works for me, 4.0.2 and 4.0.5. Here's my test code if you want to give it a try yourself.


Ext.onReady(function() {
Ext.getBody().update('<div></div>');
var state = Ext.getBody().first();
var clear = false;

new Ext.button.Button({
renderTo: Ext.getBody(),
text: 'Click',
handler: function() {
if (clear) {
Ext.util.Cookies.clear('name');
}
else {
Ext.util.Cookies.set('name', 'value', Ext.Date.add(new Date(), Ext.Date.DAY, 1000), '/');
}

clear = !clear;
}
});

setInterval(function() {
state.update('Cookie value: ' + Ext.util.Cookies.get('name'));
}, 100);
});

Thank you for your response! So I see that when I explicitly pass the domain name 'a.b.com', it doesn't clear the cookie.

When I pass in 'a.b.com' for the domain parameter, the cookie itself contains the domain parameter as '.a.b.com' (notice the dot before a.b.com) - In this case, the clearing does not work.

But, when I pass in null for the domain parameter, the cookie displays the domain parameter as 'a.b.com' (without the dot) - In this case, the clearing works.

Am I doing something wrong here?

skirtle
25 Aug 2011, 12:05 AM
The dot isn't being added by Ext, that's the browser's doing.

It does seem that the clear() method has some issues with domains though. Appears quite simple to workaround, just call set() with an expires date of new Date(0) and the other parameters set correctly.

abcdef
25 Aug 2011, 9:49 AM
The dot isn't being added by Ext, that's the browser's doing.

It does seem that the clear() method has some issues with domains though. Appears quite simple to workaround, just call set() with an expires date of new Date(0) and the other parameters set correctly.

Yep. That works. Thank you..