hesco has asked for the wisdom of the Perl Monks concerning the following question:

Perhaps I am misunderstanding what ->flush does. In the code example below, $self->{'s'} isa CGI::Session dropping sessions in /tmp/sessions. On the otherside of this redirect, I am finally getting to my destination page (thanks to ikegami who solved the riddle of the missing hyphens at this node). However I arrive with a session which does not exist in /tmp/sessions, having lost my authentication and authorization and wind up back at a login prompt.

I have been ignoring for some time that even those sessions which do get written to /tmp/sessions, seem to ignore the fact that I've set and flush'd session parameters, presumably into those files.

Can anyone with a bit more of a handle on how to use CGI::Session shed some light on a path forward, please?

Thanks,

-- Hugh Esco

$self->{'s'}->param('username',$username); $self->{'s'}->param('uid',$acct_user->{'userid'}); $self->{'s'}->param('account_code',$acct_user->{'account_code'}); $self->{'s'}->flush(); my $redirect = 1; my $url = $self->{'cfg'}->param("www.dashboard") . '?CGISESSID=' . $se +lf->{'s'}->id(); $html = $self->{'q'}->redirect( -uri => $url, -status => 303 ); print $self->{'s'}->header() unless($redirect); print $html,"\n";
if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: CGI::Session->flush() fails to store session data in file store
by almut (Canon) on May 30, 2009 at 17:20 UTC
    However I arrive with a session which does not exist in /tmp/sessions,

    Is any session file being saved there if you make a single request? (In case of doubt, delete all existing session files before doing the test request — to be sure which is which...)

    Is the cookie being sent to the domain that you redirect to? If that domain is different from the original domain that did set the cookie, it might not be getting sent at all by the browser...  just an idea.   Update: ah, overlooked that you're including the session ID in the URL... so ignore that question.

    Use Firefox's LiveHTTP Headers add-on, for example, to debug which headers/cookies are being exchanged.

Re: CGI::Session->flush() fails to store session data in file store
by shmem (Chancellor) on May 30, 2009 at 17:25 UTC

    Hmm. What's in your param("www.dashboard") ? could it be that there's something odd about the contructed $url (i.e. multiple '?' or a missing '/') ? I'd warn $url and look into the apache error log.

    Also, the preferred method to pass a session-ID is in a cookie, not in http query parameters.

Re: CGI::Session->flush() fails to store session data in file store
by Anonymous Monk on May 31, 2009 at 08:42 UTC
    Why aren't you error checking?
Re: CGI::Session->flush() fails to store session data in file store
by hesco (Deacon) on Jun 01, 2009 at 15:17 UTC
    My gratitude to the anonymous monk who reminded me of the power '$!' and a simple 'or die'. Permissions issue, and my application now seems to be writing session data to the file store.

    $ymd->{'s'}->flush() or die "Died attempting to flush session paramete +rs to the file store: ", $!;
    Now to test the redirect and the preservation of session.

    Thanks folks,
    -- Hugh

    if( $lal && $lol ) { $life++; }
      That happens to work if you're using File store, better idea to use CGI::Session->errstr()