Fellow Monasterians,

I'm having a hard time getting my head around sessions.

Background: using CGI::Application, CGI::Application::Session, and CGI::Application::Redirect on a dedicated Linux server.

Scenerio:

  1. I set a session param in one of my modules and then...
  2. redirect to an instance script in the web root that...
  3. calls another module that uses the value in the session param

Problem: The session param in Members.pm is undef.

So, what am I not getting/understanding about sessions? Thank you!

File Layout

/opt/myapps/-----+ | | | Super.pm | | | /Acmecorp/---+ | | | Login.pm | | | Members.pm | | /var/www/acmecorp/--+ | home.html | /manage/----+ | login.cgi | members.cgi

Super.pm

package Super; use warnings; use strict; use base 'CGI::Application'; use CGI::Application::Plugin::Redirect; use CGI::Application::Plugin::Session; (my $http_host = $ENV{'HTTP_HOST'}) =~ s/(www.)([a-zA-Z0-9\-\.]+)/$2/ +; $self->session_config( COOKIE_PARAMS => { -name => 'MY_SESSID', -expires => '+8h', -path => '/', -domain => ".".$http_host, }, SEND_COOKIE => 1, );

Login.pm

package Login; use base qw(Super); ****login codes goes here and if successful: ***** $self->session->param( 'member_id' => $member_id ); return $self->redirect('/manage/members.cgi'); # I could pass it with return $self->redirect('/manage/members.cgi?id= +'.$member_id), but clunkier

members.cgi

#!/usr/local/bin/perl -T use lib "/opt/myapps/"; use Acmecorp::Members; my $app = Acmecorp::Members->new(); $app->run();

Members.pm

package Members; use base qw(Super); my $member_id = $self->session->param( 'member_id' ); **** query the DB with the member's id *****
—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to CGI::App session params losing values between redirects by bradcathey

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.