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

Mike.G hylinux at gmail.com
Tue Jun 10 18:26:57 PDT 2008


thanks Qiang.

谢谢。 我已经找到问题了。
主要是由于那个cookie的设置问题 移掉secure这个参数就可以了。

包的问题,是的。我在调试的时候加上的。不过还是谢谢。我会把它们改掉的。
刚看了secure参数的说明,都是它若的祸
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.

所以去掉它就没有问题了。


2008/6/11 Qiang <shijialee at gmail.com>:

> Mike.G wrote:
> > 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?*_
> >
> >
>
> 我用 CGI::Application 但并不怎么使用 CGI::Application::Plugin::Session
> (缩为 CAP::Session)。 大致看了你的例子, script 每次运行都会调用 sub
> show_register 里的 $this->session->param('loginname') 来检查用户是否已登
> 录,如果没有登录,$this->session 的调用就会生成一个新的 CGI::Session
> object 因此生产一个新 session id. 你的 script 没有登录的那部分,即每次都
> 是一个非登录的用户访问,自然每次都拿到一个新 session id 了。
>
> 另外,CGI::Application 里一般都在 base class 里把要用到的 CAP 的 plugins
> load 进去,例如 CAP::DBH, CAP::ConfigAuto 等,没有必要在子包里在 use 了。
>
> > thanks
> >
> >
> > Mike.G
>
> HTH,
>
> Qiang
> _______________________________________________
> China-pm mailing list
> China-pm at pm.org
> http://mail.pm.org/mailman/listinfo/china-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/china-pm/attachments/20080611/cfd5854d/attachment-0001.html 


More information about the China-pm mailing list