CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
To Kill A Cookie

 



pu_nk
journeyman

Apr 19, 2001, 8:49 PM

Post #1 of 5 (292 views)
To Kill A Cookie Can't Post

Hey everyone,

So my problem is Cookies. (an cant get this...)

ok.. I set the cookie in a file called signup.pl
and i read the cookie in view.pl
now when i want my users to logout i delete the cookie in logout.pl I delete it with the following code.

print "Set-Cookie: username=the_user; expires=\"Wed 2 Jan 1987 23:59:59 GMT\"\n";

But if they dont log out and they sign up a second time or their friend does with the same browser the cookies get all messed up. the new cookie sets but it is with the other on. i make the program delete any cookies set when they sign up but that does not seem to work.

in my code do i have to set "the_user" to the user that is loging off ? or cant i just set the cookie "username" to an older date and it gets deleted..

Any ideas?



pu_nk
journeyman

Apr 20, 2001, 9:13 AM

Post #2 of 5 (284 views)
Re: To Kill A Cookie [In reply to] Can't Post

Or is there a way you can delete a cookie with CGI qw(:standard); ??
I am create and read a cookie.. but how do i delete a cookie when the user wants to log in as a different person without closing the browser ?



Jasmine
Administrator / Moderator

Apr 20, 2001, 9:20 PM

Post #3 of 5 (277 views)
Re: To Kill A Cookie [In reply to] Can't Post

To delete a cookie using CGI.pm, you would simply set the -expires argument to a negative number, such as -3d. According to the CGI.pm manual, this deletes the cookie "immediately".

Not providing the -expires parameter would delete the cookie when the browser session is over (eg, when the browser is closed).

Examples:

Setting the Cookie

Code
  
$c = cookie (
-name => 'thiscookie',
-value => {
1 => 'one',
2 => 'two',
3 => 'etc.',
},
-expires => '+3y',
);

print header( -cookie => $c );

Deleting the Cookie

Code
  
$c = cookie (
-name => 'thiscookie',
-value => {
1 => 'one',
2 => 'two',
3 => 'etc.',
},
-expires => '-3d', # to delete immediately
# or leave the above line out to
# have it expire when the browser closes
);

print header( -cookie => $c );

Hope this helps!



pu_nk
journeyman

Apr 21, 2001, 7:41 PM

Post #4 of 5 (270 views)
Re: To Kill A Cookie [In reply to] Can't Post

Great! , Thank you id di help with using CGI.pm
But just a quick question for future stuff. Do the values have to match to delete the cookie or just the name of the cookie ?



Jasmine
Administrator / Moderator

Apr 21, 2001, 8:43 PM

Post #5 of 5 (268 views)
Re: To Kill A Cookie [In reply to] Can't Post

Just the name of the cookie :)


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives