Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

CGI::Application::Plugin::Session is creating multiple sessions

by bradcathey (Prior)
on Jul 27, 2023 at 12:17 UTC ( [id://11153594]=perlquestion: print w/replies, xml ) Need Help??

bradcathey has asked for the wisdom of the Perl Monks concerning the following question:

In a CGI::Application ecomm app I'm using CGI::Application::Plugin::Session. When adding an item to the cart:

  • a instance script calls Cart.pm
  • session is started
  • a cookie is written
  • an order_id created and assigned to the session

Code that creates session:

$self->session_config( COOKIE_PARAMS => { -name => 'ECOMM_SESSID', -expires => '+4h', -domain => '.mysite.com', }, SEND_COOKIE => 1 ); CGI::Session->name('ECOMM_SESSID');

A variable dump when viewing the cart shows:

session_id = 123456789 $self->session->param('order_id') = 4321

And the browser Inspector shows:

cookie: ECOMM_SESSID

All good.

The problem comes when calling the next instance script for checking out. In sub cgiapp_prerun, the existence of the order_id is checked. A variable dump when viewing here shows:

session_id = 987654321 <= a different id than above $self->session->param('order_id') = null <= no value

And the browser Inspector shows:

cookie: CGISESSID <== ECOMM_SESSID is missing and instead...

Each time the new instance script is fired, a new session is created. Interestingly, if I return to the cart, all the original values remain.

Bottom line: when firing a new instance script, a new session is started and the cookie is not being written. So, what am I not getting?

(Note: this is similar to Re: Re: Re: Stay aware of security but the proposed solution didn't work

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re: CGI::Application::Plugin::Session is creating multiple sessions
by NERDVANA (Curate) on Jul 27, 2023 at 22:23 UTC
    Interestingly, if I return to the cart, all the original values remain.
    Perhaps your cart URL ends with a slash, making it a different path than the rest? I notice your sample code above didn't include -path  => '/', which is present in the examples on CGI::Application::Plugin::Session.
Re: CGI::Application::Plugin::Session is creating multiple sessions
by bradcathey (Prior) on Jul 29, 2023 at 17:42 UTC

    Solved my issue. PEBKAC error. The reason is was recreating two sessions with the same name but different ID's is that the shipping module was using a different domain name. So, the introduction of a new domain name was forcing a new session. Backstory: I had set this up as a staging site, but after pushing it live, forgot to adjust the link to shipping. Finally saw it in the URL. Insert head slap

    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: CGI::Application::Plugin::Session is creating multiple sessions
by Anonymous Monk on Jul 27, 2023 at 23:03 UTC
    Minimal example?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11153594]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-05-25 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found