Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: CGI::Session and cookie expiration

by bmann (Priest)
on Oct 18, 2004 at 21:43 UTC ( [id://400330]=note: print w/replies, xml ) Need Help??


in reply to Re: CGI::Session and cookie expiration
in thread CGI::Session and cookie expiration

I think it's a bug too, but the first call to header just drops all arguments - passing a CGI object is irrelevant (to header, !1 was talking about new). Here's sub header() from CGI::Session v3.95

sub header { my $self = shift; my $cgi = $self->{_SESSION_OBJ}; unless ( defined $cgi ) { require CGI; $self->{_SESSION_OBJ} = CGI->new(); return $self->header(); } my $cookie = $cgi->cookie($self->name(), $self->id() ); return $cgi->header( -type => 'text/html', -cookie => $cookie, @_ ); }

The first call to CGI::Session::header instantiates a CGI object ($self->{_SESSION_OBJ}), then calls $self->header() without any of the parameters originally passed. The second call, the CGI object already exists and sub header handles all the arguments.

Here's a minimal patch for CGI::Session (untested)

1222c1222 < return $self->header(); --- > $cgi = $self->{_SESSION_OBJ};

A workaround for the OP would be to call it twice - ie

# call header to instantiate CGI object, but throw away the result $sess->header(); # _now_ print the header print $sess->header(expires => '+1M'); __END__ output: Set-Cookie: CGISESSID=e438a0cb3647f362bd9934d048dca443; path=/ Expires: Mon, 18 Oct 2004 21:52:43 GMT Date: Mon, 18 Oct 2004 21:42:43 GMT Content-Type: text/html; charset=ISO-8859-1

Update: modified the patch

Update 2: went to rt.cpan.org, and !1's patch is almost the same...

Replies are listed 'Best First'.
Re^3: CGI::Session and cookie expiration
by !1 (Hermit) on Oct 19, 2004 at 14:29 UTC

    To further clarify, I was referring to this:

    > cat cgipass.pl #!/usr/bin/perl -l use CGI::Session; use CGI; my $cgi = CGI->new(); my $sess = CGI::Session->new(undef, $cgi, {Directory=>'.'}); print $sess->header(expires=>'+1M'); > perl cgipass.pl Set-Cookie: CGISESSID=e433f7dae02dd6e0baf79d0d993250cd; path=/ Expires: Thu, 18 Nov 2004 14:17:27 GMT Date: Tue, 19 Oct 2004 14:17:27 GMT Content-Type: text/html; charset=ISO-8859-1
      Thanks for the clarification. When I originally wrote my reply I thought you meant a CGI object as the second parameter to header, not new - even though you clearly said new in your original post.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://400330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found