I have the following code to test setting a cookie and retrieving a CGI::Session id() from the cookie.   Each time I click on the link "check it's the same", I get a different session id displayed.   I've checked that the browser's actually receiving a cookie and it is. And the value's different every time.

What am I doing wrong? Thanks.

package ImagesAdmin; use base CGI::Application; use strict; use ImagesES::Conf; use CGI::Session; use File::Spec; sub setup { my $self = shift; my $q = $self->query(); $self->param('conf' => ImagesES::Conf->new()); $self->param('session' => new CGI::Session(undef, $q, {Directory => $self->param('conf') +->{'cgi_session_dir'}})); $self->param('session')->expire( $self->param('conf')->{'admin_ses +sion_expire'}); $self->param('this_url' => $q->url(-absolute=>1)); my $cookie = $q->cookie(-name => 'sid', -value => $self->p +aram('session')->id(), -path => $self->pa +ram('conf')->{'admin_cookie_path'}); $self->header_props(-cookie => $cookie); $self->start_mode('mainmenu'); $self->run_modes( mainmenu => 'mainmenu', logout => 'logout', ); } sub mainmenu { my $self = shift; my $q = $self->query(); my $logout_link = $self->param('this_url') . '?rm=logout'; my $output = $q->start_html(); $output .= $q->p( 'your session id is', $self->param('session')->i +d() ); $output .= $q->p( $q->a({href=> $self->param('this_url')}, 'check +it\'s the same') ); $output .= $q->p( $q->a({href=> $logout_link}, 'logout')); $output .= $q->end_html(); return $output; } sub logout { my $self = shift; my $q = $self->query(); $self->param('session')->delete(); my $output = $q->start_html(); $output .= $q->p('logged out!'); $output .= $q->p( $q->a({href=> $self->param('this_url')}, 'log in +') ); $output .= $q->end_html(); return $output; } 1;

2003-06-14 edit ybiC: <readmore> tags around block of code


In reply to CGI::Application CGI::Session problem by fireartist

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.