Cookies Reading and Writing

How I make a cookie:
print "Set-Cookie: NAME=$cid
";

This is how I read a cookie:
$cdata = $ENV{'HTTP_COOKIE'}; ($name,$cid) = split(/=/,$cdata);

How do I erase the cookie, or replace it?

Comments

  • Just set the cookie again using the Set-Cookie Header... if you want to erase it - leave the value blank. I don't know for certain, but there could be also an argument to give the browser information on the "time to live" for this cookie, if it is so - set this on yesterday or some day in the past - then the cookie will be erased.


    best regards,

    sebastian mohrenstecher
    executive secretary
    net::allies

    www.net-allies.de
    info@net-allies.de

  • Hi,

    Just to follow up this:-

    : I don't know for certain, but there could be also an argument
    : to give the browser information on the "time to live" for this
    : cookie,

    There is and it's the expires argument.

    print "Set-Cookie: NAME=$cid; expires=;
    ";

    Leave it blank like that (or not put it in at all) and the cookie lasts as long as the web browser is open. Close the web browser, it's gone. That's called a session cookie. If you put a date in there (the scalar output of a function like gmtime in Perl will probably do it well) then it'll expire on that date. Think max cookie life is 10 years??? But the user will probably chuck their computer on the rubbish heap before then....

    Hope all that's right!

    Jonathan

    -------------------------------------------
    Count your downloads:
    http://www.downloadcounter.com/
    And host your site:
    http://www.incrahost.com/
    Don't say I never give you anything... ;-)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories