Hello,

You should check out CGI::Application.

I put this example on the CGI::Application wiki a while ago. It abstracts the use of CGI::Application to a single use() statement:

#!/usr/local/bin/perl use warnings; use strict; TestApp->new->run; package TestApp; use base qw|CGI::Application|; use CGI::Application::Plugin::AutoRunmode; use CGI::Application::Plugin::Session; sub default : StartRunmode { my $self = shift; my $output; # get current access count my $access_count = $self->session->param('access_count') || 0; # increment access count $access_count++; # store new access count in session $self->session->param(access_count => $access_count); # get CGI object out of application my $q = $self->query; #build output $output = $q->start_html( -title => 'access count application'); $output .= $q->div("accessed $access_count time(s) this session"); $output .= $q->div($q->a({-href => $q->self_url}, 'access again')); $output .= $q->end_html; # give output to app to send to user return( $output ); }

This code simply increments a session counter each time the user accesses the page.

In your code, you'd make a login and an options runmode (method). In the login runmode, put the user's database id in the session upon successful login. In the options runmode, check to see if the user's id is in the session (and valid!) before continuing.

Enjoy

trwww


In reply to Re: CGI::Session Usage Doubt by trwww
in thread CGI::Session Usage Doubt by poolboi

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.