[cgiapp] the plugin CGI::Application::Plugin::Session issue

Mike.G hylinux at gmail.com
Tue Jun 10 03:31:31 EDT 2008


Hi, list
I got one issue when I use the plugin CGI::Application::Plugin::Session

I have a parent package(Class), named "FWebApp",
and this class extends the CGI::Application.
I did some setting work in the method cgiapp_init

like this:

sub cgiapp_init {
    my $this = shift;

    #get the database configuration
    my $datasource = $this->cfg('data_source');
    my $data_user = $this->cfg('data_username');
    my $data_auth = $this->cfg('data_userauth');
    my $attr = $this->cfg('data_attr');

    #configuration the Database
    $this->dbh_config($datasource,
        $data_user,
        $data_auth,
        $attr);


    #configuration the Session
    $this->session_config(
        CGI_SESSION_OPTIONS => [
        "driver:mysql",
        $this->query,
        {
            Handle=>$this->dbh
        }],

        COOKIE_PARAMS => {
        -domain => $this->cfg('site_domain'),
        -expires=>'+40m',
        -path=>'/',
        -secure=>1,
        },

    );

    #set the template path
    $this->tmpl_path($this->cfg('template_path'));



and the session configuration look like is ok.

and so, just now, i assume I have a action: it is register .
so, I will write a new module named:

package FWebApp::Register;
=head1  NAME

FWebApp::Register - show the register page

=head1  SYNOPSIS

extends the Class FWebApp,
show the register page

=cut
use strict;
use warnings;
use base qw/FWebApp/;
use CGI::Application::Plugin::AutoRunmode;
use CGI::Application::Plugin::DBH qw/dbh_config dbh/;
use CGI::Application::Plugin::ConfigAuto qw/cfg/;
use CGI::Application::Plugin::Session;


# the default requirement mode
# show the register page.
sub show_register: StartRunmode {
    my $this = shift;

    # if that user had login, we will jump to home page
    my $template = undef;
    if ( $this->session->param('loginname') ) {
        $template = $this->load_tmpl('had_login.html');
        $template->param('HOMEPAGE', 'index.html');
    } else {
        $template = $this->load_tmpl('register.html');
    }


    return $template->output;

}




1;


it is extends FWebApp, but when I had prepared a script:
like this:
#!/usr/local/bin/perl -w -T
use strict;
use lib qw(. ../lib);
use CGI::Application::Plugin::ConfigAuto;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use FWebApp::Register;

my $app = FWebApp::Register->new(
    PARAMS => {
        cfg_file => 'config.pl' } );

$app->run;


*when I refresh that script, we always got the difference session id, why?*


thanks


Mike.G


More information about the cgiapp mailing list