If you're using CGI.pm (or any such modules), this may help you...

use CGI qw(:cgi); # Name of this script, for example my $script = script_name(); my $query = get_param('action') || 'start';' my %actions = ( start => \&do_start, login => \&do_login ); &{ $actions{$query} } sub do_start { my $cookie = cookie('cookie_name'), # Check $cookie value, note that cookies # aren't to be trusted 100% if($cookie) { showsecretcontent(); } else { show_loginpage(); } } sub showsecretcontent { # prints secret content page } sub show_loginpage { # prints login page # Have a hidden field and set its name as 'action' # and its value to 'login' } sub do_login { # process results do_refresh(); } sub do_refresh { my $cookie = ( -name => 'mycookie', -value => 'youareloggedin', -path=>'/', -expires => '+1y' ); print header (-cookie => $cookie); start_html(); print qq~<META HTTP-EQUIV ="Refresh" CONTENT = "2 ; URL=$script">~; print p("You've successfully logged in. Please wait while you're re- +direced..."); end_html(); }
Hope that helps...

In reply to Re: Cookies by kiat
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.