A short but functional example:
#!/usr/bin/perl -Tw use strict; use CGI; use CGI::Session qw/ip-match/; my $q = new CGI; my $name = "name"; my $password = "password"; my $f_name = $q->param("name") || ""; my $f_password = $q->param("password") || ""; my $session = new CGI::Session(undef,$q,{Directory=>'/tmp'}); $session->expire('+1h'); my $sessionid=$q->cookie("cgisessid")||$session->param("_SESSION_ID"); my $cookie_id = $q->cookie(CGISESSID=>$session->id); $session->delete() if $q->param("out"); if (!$session->param("name") && ValidateLogin($f_name,$f_password) == 0) { Form(); } else { LogedIn(); } sub Form { print $q->header, $q->start_html, $q->start_form, "Name: ", $q->textfield({NAME=>'name',OVERRIDE=>1}), $q->br, "Password: ", $q->password_field({NAME=>'password',OVERRIDE=>1}), $q->br, $q->submit("Login"), $q->end_form, "Sesson ID: ", $session->id, $q->p,"HINT: Use 'name' and 'password' to login",$q->end_html; } sub LogedIn { $session->param("name",$q->param("name")); print $q->header({COOKIE=>$cookie_id}), $q->start_html, "LoggedIn", $q->br, "SESSION(id): ", $session->id, $q->br, "SESSION(name): ", $session->param("name"), $q->br; print $q->start_form, $q->hidden({NAME=>'out',VALUE=>1}), $q->submit("LogOut"), $q->end_form, $q->end_html; } sub ValidateLogin { my ($n,$p) = @_; $n ne $name && $p ne $password ? 0 : 1; }

Hope it helps.


In reply to Re: CGI::Session - non-stop session creation problem by Miguel
in thread CGI::Session - non-stop session creation problem by Stenyj

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.