Gossamer Forum
Quote Reply
Write Cookies
Hi,

I want to overwrite an existing cookie when someone logs out from the forum. I try to use a plugin with a hook after "logout".

The following isn't working.

Code:
package Plugins::GForum::CookieOut;
# ==================================================================

use strict;
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use GForum qw/$IN $DB $CFG/;
use GT::CGI;
use GT::CGI::Cookie;

# Inherit from base class for debug and error methods
@Plugins::GForum::CookieOut::ISA = qw(GT::Base);

# Your code begins here! Good Luck!


# PLUGIN HOOKS
# ===================================================================


sub loeschen {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'logout'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
my (@args) = @_;

# Do something useful here

my $in = new GT::CGI;

my $c = new CGI::Cookie(-name => 'lh_username', -value => '');
print $in->header( -cookie => $c );

return @args;
}

# Always end with a 1.
1;

Can someone give me a hint?


This from the forum-help doesn't worked at all:

------------------
To set a cookie:

$c = $cgi->cookie (-name => 'foo', -value => 'bar')

You would then set the cookie by passing it to the header function:

print $in->header ( -cookie => $c );
--------------------
Quote Reply
Re: [petersenj] Write Cookies In reply to
You don't need:

use GT::CGI;

or

use GT::CGI::Cookie;

You are already importing $IN which is your CGI object.

my $cookie = $IN->cookie( ... );

Last edited by:

Paul: Apr 2, 2003, 2:55 PM
Quote Reply
Re: [Paul] Write Cookies In reply to
In Reply To:
You are already importing $IN which is your CGI object.

my $cookie = $IN->cookie( ... );

Thanks!

my $header2 = $IN->cookie(-name => 'lh_username', -value => 7, -path => '/', -expires => "+31m", -domain => '.lokalhelden.de')->cookie_header() . "\n";
print $header2;

seems to work.

What is the difference to

my $cookie = $IN->cookie(-name => 'lh_username', -value => 7, -path => '/', -expires => "+31m", -domain => '.lokalhelden.de');
print $IN->header(-cookie => $cookie);

Regards
Johannes
Quote Reply
Re: [jmar] Write Cookies In reply to
I've never used cookie_header() but I expect that the first example allows you to print the cookie without actually printing the full header, whereas the second example prints the cookie as well as the rest of the header (eg, content-type).