I have cookies set when the user log in to the application. Yet I need to modify that when the user updates his profile. Can anyone tell me how to update an existing cookies? Thanks in advance.(I'm using perl).
views:
132answers:
1
+3
A:
CGI::Cookie is all you need.
To get the cookies sent to your application:
my %cookies = CGI::Cookie->fetch;
my $foo = $cookies{foo}->value;
If you're using CGI.pm to generate your headers, then sending a Set-Cookie
header just requires passing in the CGI::Cookie
object:
my $q = CGI->new;
print $q->header( -cookie => $foo );
Otherwise, use whatever header-manipulation interface is provided by the web application framework you are using.
friedo
2010-02-11 18:31:14
when i tried that, I get that:Set-Cookie: test.jpg Date: Thu, 11 Feb 2010 18:44:24 GMT Content-Type: text/html; charset=ISO-8859-1 printed on the page.I can't change with the header. So I'm having it printed it on the page, I want a way to modify the cookies without printing it.
zeina
2010-02-11 18:46:33
If you want to modify a cookie, you have to set a Cookie header. If something else is setting your header and you can't modify it, you need to seriously rethink your application architecture. The only other way to change a cookie is to do it client-side in Javascript.
friedo
2010-02-11 19:22:11
Friedo, when you say I can do that using javascript, what do you mean?Can you give me a good example please?
zeina
2010-02-12 07:24:50
@zeina: emit into your html something like `<script>document.cookie='foo=bar; expires=Thu, 11 Feb 2010 08:00:00 UTC; path=/'</script>`
ysth
2010-02-12 07:55:05
Thanks Guys, this link helped me:http://www.quirksmode.org/js/cookies.htmlThanks Friedo for your suggestion.
zeina
2010-02-12 08:13:41