For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > August 2005 > Clearing cookies









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Clearing cookies
Denzil Kruse

2005-08-16, 9:59 pm

Hi all,

I'm trying to clear a cookie using CGI::Cookies, and
can't seem to do it :(

if ($clear_cookie eq 'yes') {

my %cookies = fetch CGI::Cookie;

print "getting cookie<br>";

if ($cookies{'id'}) {

print "clearing cookie<br>";
$cookies{'id'}->expires('-1s');
print "cleared cookie<br>";
}
}

I'm getting the "cleard cookie" message, but it is
still there.

Denzil



________________________________________
____________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

Wiggins d'Anconia

2005-08-16, 9:59 pm

Denzil Kruse wrote:
> Hi all,
>
> I'm trying to clear a cookie using CGI::Cookies, and
> can't seem to do it :(
>
> if ($clear_cookie eq 'yes') {
>
> my %cookies = fetch CGI::Cookie;
>
> print "getting cookie<br>";
>
> if ($cookies{'id'}) {
>
> print "clearing cookie<br>";
> $cookies{'id'}->expires('-1s');
> print "cleared cookie<br>";
> }
> }
>
> I'm getting the "cleard cookie" message, but it is
> still there.
>
> Denzil
>


To clear the cookie in the user's client (browser) you have to "set" the
cookie again by printing it in the response headers. You are only
setting the local expiration, to have that maintained across the rest of
the session you have to tell the browser about it, which is done by
passing it back as if you were setting it initially.

HTH,

http://danconia.org
Denzil Kruse

2005-08-16, 9:59 pm



--- Wiggins d'Anconia <wiggins@danconia.org> wrote:

> Denzil Kruse wrote:
>

<snip>

> To clear the cookie in the user's client (browser)
> you have to "set" the
> cookie again by printing it in the response headers.
> You are only
> setting the local expiration, to have that
> maintained across the rest of
> the session you have to tell the browser about it,
> which is done by
> passing it back as if you were setting it initially.
>
> HTH,
>
> http://danconia.org
>


Okay, that makes sense. Thanks for the help!

Denzil



________________________________________
____________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

Denzil Kruse

2005-08-17, 4:59 pm


--- DBSMITH@OhioHealth.com wrote:

> can you give a syntax example?


Here is a piece of what I'm doing:
------------------------------------
if ($clear_cookie eq 'yes') {

my %cookies = fetch CGI::Cookie;

if ($cookies{'id'}) {

$cookies{'id'}->expires('-1s');

print "Set-Cookie: $cookies{'id'}\n";
}
}
print "Content-type: text/html\n\n";
--------------------------------------------------

I'm just following the instructions at:

http://perldoc.perl.org/CGI/Cookie.html

This whole cookie thing is new to me. Never wanted to
use them before because they were out of my control,
browsers might block them, or people might not
understand what they are and get all paranoid. Or do
understand and get paranoid :o)

Denzil




________________________________________
____________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

Denzil Kruse

2005-08-17, 4:59 pm

I'm still having a problem clearing the cookie, or at
least with the browser realizing it has been cleared.

What happens is this: The cookie is set, and my
program behaves as it is supposed to. When I decide
to clear it, I do it and display a form which will
recreate the cookie once the form is filled out and
the submit button is pushed.

So it clears the cookie and displays the form. I look
under C:\Documents and Settings\Owner\Cookies on my
local computet running the browser, and I see the
cookie disappear. But when I press the button on the
form once, the browser behaves as if the cookie is
still set. If I then press the button a second time,
it behaves as if the cookie isn't there (correctly).

I do have an apache rewrite rule in effect, maybe that
is causing it to have to do it twice?

Denzil



________________________________________
____________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs

Denzil Kruse

2005-08-17, 4:59 pm

Okay, never mind. There was an error elsewhere in my
code.

Denzil

--- Denzil Kruse <denzilphp@yahoo.com> wrote:

> I'm still having a problem clearing the cookie, or
> at
> least with the browser realizing it has been
> cleared.
>
> What happens is this: The cookie is set, and my
> program behaves as it is supposed to. When I decide
> to clear it, I do it and display a form which will
> recreate the cookie once the form is filled out and
> the submit button is pushed.
>
> So it clears the cookie and displays the form. I
> look
> under C:\Documents and Settings\Owner\Cookies on my
> local computet running the browser, and I see the
> cookie disappear. But when I press the button on
> the
> form once, the browser behaves as if the cookie is
> still set. If I then press the button a second
> time,
> it behaves as if the cookie isn't there (correctly).
>
> I do have an apache rewrite rule in effect, maybe
> that
> is causing it to have to do it twice?
>
> Denzil
>
>
>
> ________________________________________
____________
> Start your day with Yahoo! - make it your home page
> http://www.yahoo.com/r/hs
>
>
> --
> To unsubscribe, e-mail:
> beginners-cgi-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-cgi-help@perl.org
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>
>
>



________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com