Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I update value of an existing cookie

Status
Not open for further replies.

coolnz

Technical User
Joined
Jan 19, 2007
Messages
1
Location
NZ
Hello

I am crumbling over perl cookies

I'm using CGI::Cookies
and am reading the perl documentation for CGI::Cookies at
I can set new cookies as follows:-

$cookie1 = new CGI::Cookie(-name=>$cookiename1,-value=>$defaultcookievalue1,-expires=>'+3M');
$cookie2 = new CGI::Cookie(-name=>$cookiename2,-value=>$defaultcookievalue2,-expires=>'+3M');
print header(-cookie=>[$cookie1,$cookie2]);

Easy great I've tried it and it works.

Now I have my cookies, I've learned how to fetch the cookies as follows:-

%mycookies = fetch CGI::Cookie;

I can extract the values like so:-

$mycookies{$cookiename1}->value();

Now I've fetched the value all I want to do is alter and save it


The documentation says do this:-

@new_value = $c->value(['a','b','c','d']);

and explains that it is updating the cookie and returning the updated value to the array

What is confusing me is the use of $c looking back up the documentation $c was used for
creating a NEW cookie with default values.

My cookie already exists and all I want to do is change it's value.

Do I have to read the cookie, delete it, manipulate the values i got from it, generate a new cookie with the same name and updated values and then save it?

I'm lost

Can anyone help before I crumble to dust?

just a simple example of updating the value of an exisiting cookie using CGI::Cookies would help me a lot
 
$c is the cookie object, when you retrieve the cookie you store its info the the $c instance of CGI::Cookie, this could be $oc, or $orig_cookie, as long as you created an instance, a la
Code:
$oc=new CGI::Cookie;

Just read the cookie, update the values, reset the expiry, and then 'bake' it, and it'll be overwritten
Code:
$c->bake;

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top