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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting/Amending Cookies 1

Status
Not open for further replies.

Tyger

Programmer
Sep 19, 2001
21
GB
Having been able to set cookies using the Set-Cookie: command I would now like to be able to alter them by deleteing specific cookies, and deleting all cookies/the cookie file.

I'm pretty certain this must be possible, but as yet haven't been able to find out how.

Thanks.
 
To delete a cookie, if I remember right I think you basically give it a negative "lifetime" - lifetime is one of the parameters you can supply when creating a cookie.

I assume you are talking about cookies in the context of a cgi script - I don't think you can delete "all" the cookies in the cookie file. I believe you can only affect specific cookies.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
The following uses CGI.pm to set cookies. If the cookie already exists, it is overwritten with the new value. You can run this once to set the cookies. Then, change the values in this code, run it again and see the cookies change.

Code:
#!/usr/local/bin/perl
use CGI;
$query = new CGI;
$thisCGI = $query->url();

# try to read the cookie via the CGI.pm method
$cook1 = $query->cookie(-name=>'cook1');
$cook2 = $query->cookie(-name=>'cook2');

$cookie1 = $query->cookie(-name=>"cook1",
    -value=>'appetizer',
    -expires=>"+1h");

$cookie2 = $query->cookie(-name=>"cook2",
    -value=>'entre',
    -expires=>"+1h");


# print the cookie in the header.
print $query->header(-cookie=>[$cookie1,$cookie2]);
print $query->start_html(-title=>"cook this");
print &quot;<P>Cook1 is $cook1 and Cook2 is $cook2</P>&quot;;
print $query->end_html;

HTH Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top