Sorry for my completely bogus first reply *blush*

While it sounds good, it doesn't point you into the right direction.

CGI::Session encapsulates CGI to store parameters, cookies and so on in a serialized data structure, so you don't need to use both of them. Choose one, use one.

Maybe you mended your confusion in the meantime - anyways:

2) I am confused as to how the username is picked up correctly, if I use'$session->delete();' in the script? (I don't see the 'cgisess_............' in the /tmp folder and I am sure it is getting deleted )

You grab the params before the call to $session->delete()

my $user = $session->param( "user" ); my $sid = $session->id(); my $cookie = $q->cookie( -name => $session->name(), -value => $sid, -expires => "+5" ); my $nextpage = 'test_cgi_session.pl'; $session->delete();

pass them to your template

$template->param( user => $user ); $template->param( sessionid => $sid );

and have them stuck into the value attribute of your inputs

<input type="input" name="user" value="<tmpl_var name=user>" /> </tr></td> <tr><td> <input type="input" name="sessionid" value="<tmpl_var name=sessionid>" + size="100" />

so it would be rather odd for $user not to show up in the text field.

3) Also, I am not sure why I don't need '$session->load_param(); ' call?

You need the $session->load_param() call if the only value passed into your cgi is the session ID, and you want to restore the params from the previously stored serialized data structure, i.e. if there wasn't any user name passed in, and you want the username to be passed to subsequent pages nonetheless - just the opposite of what you expected your script to do ;-)

I am really not sure if I am using CGI::Session correctly

Those who are sure, aren't ;-)

Look for the method 'dump' in CGI::Session and include dump($session) in your output to see what's in that session thing.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re^3: Confusion using CGI Session by shmem
in thread Confusion using CGI Session by stumbler

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.