the plugin CGI::Application::Plugin::Session issue

View: New views
5 Messages — Rating Filter:   Alert me  

the plugin CGI::Application::Plugin::Session issue

by Mike.G :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Re: the plugin CGI::Application::Plugin::Session issue

by Cees Hek :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jun 10, 2008 at 5:31 PM, Mike. G <hylinux@...> wrote:
> Hi, list
> I got one issue when I use the plugin CGI::Application::Plugin::Session
>
**SNIP**

>
>        COOKIE_PARAMS => {
>        -domain => $this->cfg('site_domain'),
>        -expires=>'+40m',
>        -path=>'/',
>        -secure=>1,
>        },
>
>    );
>
**SNIP**
>
> *when I refresh that script, we always got the difference session id, why?*

Hi Mike,

That is usually due to a cookie problem.  Make sure the cookie is
actually being set in the browser, and that it is being returned back
to on the next request.  The Live HTTP Headers plugin for firefox is
really handy for this.

If the cookie isn't being set, then I would remove some of the cookie
options that you have set above.  Start without any cookie options and
then start adding them in until you find the problem.

There is another problem that can sometimes cause this.  CGI::Session
sometimes has issues flushing the session to the database unless it is
done explicitly.  I believe the main cause of this is the database
handle going away before CGI::Session has a chance to flush it to the
database.  Adding a call to flush the session in the teardown stage
usually solves that.  Just add the following to your base class:

__PACKAGE__->add_callback('teardown', sub {
    my $self = shift;
    $self->session->flush;
});


Cheers,

Cees

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Re: the plugin CGI::Application::Plugin::Session issue

by Mike.G :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, Cees,  I got it. thanks very much.
I had remove the cookie parameter named "secure", it work find now.
so, I am not very clean know what's that parameter. look like I need find
some document about the cookie setting.
and thank a lot.

Mike.G


2008/6/11 Cees Hek <ceeshek@...>:

> On Tue, Jun 10, 2008 at 5:31 PM, Mike. G <hylinux@...> wrote:
> > Hi, list
> > I got one issue when I use the plugin CGI::Application::Plugin::Session
> >
> **SNIP**
> >
> >        COOKIE_PARAMS => {
> >        -domain => $this->cfg('site_domain'),
> >        -expires=>'+40m',
> >        -path=>'/',
> >        -secure=>1,
> >        },
> >
> >    );
> >
> **SNIP**
> >
> > *when I refresh that script, we always got the difference session id,
> why?*
>
> Hi Mike,
>
> That is usually due to a cookie problem.  Make sure the cookie is
> actually being set in the browser, and that it is being returned back
> to on the next request.  The Live HTTP Headers plugin for firefox is
> really handy for this.
>
> If the cookie isn't being set, then I would remove some of the cookie
> options that you have set above.  Start without any cookie options and
> then start adding them in until you find the problem.
>
> There is another problem that can sometimes cause this.  CGI::Session
> sometimes has issues flushing the session to the database unless it is
> done explicitly.  I believe the main cause of this is the database
> handle going away before CGI::Session has a chance to flush it to the
> database.  Adding a call to flush the session in the teardown stage
> usually solves that.  Just add the following to your base class:
>
> __PACKAGE__->add_callback('teardown', sub {
>    my $self = shift;
>    $self->session->flush;
> });
>
>
> Cheers,
>
> Cees
>
> #####  CGI::Application community mailing list  ################
> ##                                                            ##
> ##  To unsubscribe, or change your message delivery options,  ##
> ##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
> ##                                                            ##
> ##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
> ##                                                            ##
> ################################################################
>
>

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Re: the plugin CGI::Application::Plugin::Session issue

by Mike.G :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

got that optional mean:
secure flag
           If the "secure" attribute is set, the cookie will only be sent to
your script if the CGI request is occurring on a secure channel, such as
           SSL.


thanks

Mike.G


2008/6/11 Mike. G <hylinux@...>:

> Hi, Cees,  I got it. thanks very much.
> I had remove the cookie parameter named "secure", it work find now.
> so, I am not very clean know what's that parameter. look like I need find
> some document about the cookie setting.
> and thank a lot.
>
> Mike.G
>
>
>
>>
>>
>

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


Re: the plugin CGI::Application::Plugin::Session issue

by George Hartzell-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Cees Hek writes:
 > On Tue, Jun 10, 2008 at 5:31 PM, Mike. G <hylinux@...> wrote:
 > > Hi, list
 > > I got one issue when I use the plugin CGI::Application::Plugin::Session
 > >
 > **SNIP**
 > >
 > >        COOKIE_PARAMS => {
 > >        -domain => $this->cfg('site_domain'),
 > >        -expires=>'+40m',
 > >        -path=>'/',
 > >        -secure=>1,
 > >        },
 > >
 > >    );
 > >
 > **SNIP**
 > >
 > > *when I refresh that script, we always got the difference session id, why?*
 >
 > Hi Mike,
 >
 > That is usually due to a cookie problem. [...]

In addition to what Cees mentioned, you might need to double check
that the system clock on the server is correct.

g.

#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################

LightInTheBox - Buy quality products at wholesale price