This isn't so bad if you use CGI::Session to do the hard lifting. At the very least read the CGI::Session::Tutorial to get a good foundation (and read merlyn's article as well, if you haven't already).

Here is a quick-n-dirty CGI script that also uses CGI::Application:

use CGI::Application; my $webapp = WebApp->new(); $webapp->run(); package WebApp; use strict; use warnings; use CGI::Session; use base 'CGI::Application'; sub setup { my $self = shift; $self->start_mode('index'); $self->mode_param('rm'); $self->run_modes([qw(login index)]); } sub cgiapp_prerun { my $self = shift; my $q = $self->query(); my $session = CGI::Session->new(undef, $q, {Directory=>"/tmp"}); if ($q->param('cm') eq 'Login') { $session->param(logged_in => 1); $session->param(username => $q->param('username')); } elsif ($q->param('cm') eq 'Logout') { $session->delete; } # Redirect to login, if necessary unless ($session->param('logged_in')) { $self->prerun_mode('login'); } if ($session) { my $cookie = $q->cookie(CGISESSID => $session->id); $self->header_props(-cookie=>$cookie); $self->param(session => $session); } } sub login { my $self = shift; my $q = $self->query(); return $q->start_html(-title => 'Login') . $q->start_form() . $q->p('Username: ', $q->textfield('username')) . $q->p('Password: ', $q->password_field('password')) . $q->submit(cm => 'Login') . $q->end_form() . $q->end_html() ; } sub index { my $self = shift; my $q = $self->query(); my $session = $self->param('session'); my $username = $session->param('username'); return $q->start_html(-title => 'Welcome') . $q->p("$username is logged in!") . $q->p($q->a({href=>'?cm=Logout'},"Log out!")) . $q->end_html() ; }
Ya know ... you kinda sound like webstudorio ... anyways, hope this finally helps. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: Cookies by jeffa
in thread Cookies, how can you set one if it must be done before the header? by Anonymous Monk

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.