perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John ORourke <john-modp...@o-rourke.org>
Subject Re: Cookie questions
Date Mon, 24 Dec 2007 09:22:26 GMT
Raymond Wan wrote:
> I was wondering if it was possible to delete cookies.  I read that 
> using Javascript, cookies can be deleted by setting it to a time in 
> the past.  I'm not sure how to do it in Mason, though.  I think I know 
> how to get a cookie and also to set a new one and send it out.  But, I 
> don't know how to get an old cookie, change it, and send it back.  Or 
> even, get a cookie, *copy it*, send the copy back.  What is stopping 
> the browser from creating a second cookie with the same name?
Cookie names are unique to a given domain (the domain which can 
optionally be explicitly set using $cookie->domain ) - if you write 
another cookie with the same name and domain and path it'll overwrite 
the previous one.

> $r->err_headers_out->add ("Set-Cookie" => $cookie->as_string);

Fine, that's basically what the bake() method does.  I made a subclass 
of APR::Request::Cookie which included some hacks - try these:

Deleting:
        $val=$cookie->as_string;
        $val=~s/max-age=(\S*?)(\s*;)?//ig; # remove any existing max-age
        $val.='; Max-Age=0';
        $r->err_headers_out->add("Set-Cookie", $val);

Setting:
        $val=~s/="\/"/=\//; # firefox hack to ensure it understands the path
        $r->err_headers_out->add("Set-Cookie", $val);


hth,
John


Mime
View raw message