I have been helping the author of CGI::kSession write an updated pod, and as a result, offered to add an example of usage. Someone might find it useful (who knows how long before it hits CPAN...)
Sessions, URLs, and Cookies
use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI::kSession; use CGI::Cookie; my $cgi = new CGI; my $last_sid = $cgi->param("SID"); my $c = new CGI::Cookie(-name=>'SID',-value=>$last_sid); my ($id, $key, $value); my $s = new CGI::kSession(path=>"/tmp/"); print $cgi->header(-cookie=>$c); print $cgi->start_html(); if ($last_sid) { # note: the following I used for mozilla - your mileage ma +y vary my $cookie_sid = (split/[=;]/, (fetch CGI::Cookie)->{SID}) +[1]; if ($cookie_sid) { print "<b>We are now reading from the cookie:</b><p>"; $id = $s->id($cookie_sid); $s->start($cookie_sid); print "The cookie's id: $cookie_sid<br>"; print "Here's the test_value: ".$s->get("test_key")."< +br>"; } else { print "<b>We are now reading from the URL parameters: +</b><p>"; $id = $s->id($last_sid); $s->start($last_sid); print "Last page's id: $last_sid<br>"; print "Here's the test_value: ".$s->get("test_key")."< +br>"; } } else { print "<b>Here we will set the session values:</b><p>"; $s->start(); $id = $s->id(); print "My session id: $id<br>"; $s->register("test_key"); $s->set("test_key", "Oh, what a wonderful test_value this +is..."); print "Here's the test_value: ".$s->get("test_key")."<br>" +; } # note: the first click will set the session id from the URL t +he # second click will retrieve a value from the cookie print "<a href=".(split/\//,$0)[-1]."?SID=$id>Next page</a>"; print $cgi->end_html();

In reply to CGI::kSession example by oubiwann

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.