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

Cees Hek ceeshek at gmail.com
Tue Jun 10 19:59:38 EDT 2008


On Tue, Jun 10, 2008 at 5:31 PM, Mike. G <hylinux at gmail.com> 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


More information about the cgiapp mailing list