I'm writing my own cookies as part of a webserver I'm making using NodeJS (i.e. not using any packages). I've been able to do this just fine using something like:
response.writeHead(200, {
'Set-Cookie':'sesh=wakadoo'
});
However, I'd like to make my cookies more persistent than they currently are (which is to say not at all). I've tried doing something like this:
var curdate = new Date();
response.writeHead(200, {
'Set-Cookie':'sesh=wakadoo; expires='+curdate.toUTCString()
});
but alas this doesn't seem to work. chrome just ignores the expiration i set, and firefox never loads the page. My current goal is to simply give my cookie an expiration date that can be interpreted by the browser... does anybody know how to do this?
Best,
Sami
Try giving the expires some lead time, like an day. The client/server may not read it because it's expired when you submit it.
response.writeHead(200, {
'Set-Cookie':'sesh=wakadoo; expires='+new Date(new Date().getTime()+86409000).toUTCString()
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With