I'm having trouble getting a CGI::Application::Session cookie to be persistent. In other words, once the browser is closed the cookie is lost. Which is understandable because that's how cookies work, but I want to create one that is persistent and is used later if the user wants Automated logins. If I try to set the parameters such that the cookie has an expiration date, then every page I visit that is encapsulated within the same cookie/login returns me to login as if the cookie parameter for being logged in was cleared or if the cookie all together is being cleared. I'm using a combination of HTML::Template, CGI::Application, and CGI::Application::Session for a database program that I've developed. All run mode programs inherit from a parent that does a prerun to determine if the 'program' should route to the login page. If I do
my $self = shift; my $q = $self->query(); my $session = $self->session;
then when the user logs in, and I check the parameters from the log in form, compare them to the database, and set the session parameter login to true, everything works. Except, once they close their browser and come back later they have to log in again. This works perfectly like I expect, so then I go further to see if I can get automated logins to work ... If I try to create a cookie with a specific time then I end up with the user constantly logging in for every mode/page they try to visit - am I writing this incorrectly?
my $self = shift; my $q = $self->query(); my $sid = $q->cookie("CGISESSID") || undef; $self->session_config ( CGI_SESSION_OPTIONS => [ "driver:File", $q, {Directory=>'/tmp'} ], COOKIE_PARAMS => { -expires => '+1M', -secure => 1, }, SEND_COOKIE => 1, ); my $session = $self->session;
I figure I probably need to do some kind of cookie comparison or something? I don't know when/where/how to do this if this is the case. If I am being vague and we need more information of what I am doing I'll gladly write more. I just hope this is a good starting point.

In reply to CGI::Application::Session Cookies confusion by kerindar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.