Hello khippy

This is a good effort. There are however a few things I would change.

I would suggest using my to add scope to your variables in your subroutines. You are currently declaring all your vars at the top of the script and then using them all in your subs. This makes them all essentially global (at least within the code you present).

I would also suggest adding most of the code in your "Main" section to a sub called isLoggedIn() or something. Put all of that code somewhere out of the way - maybe in a module if you can.

I also highly recommend reading merlyn's column on cookie management. The code snippet he presents is quite short and the commentary is illuminating.

I have recently written a module based on the idea in that column that makes it easy to drop in to different projects that authenticate using different methods.

Of course, I'm slightly reinventing the wheel, there already exists Apache::Session and CGI::MxScreen which do similar things and probably more. So mine probably will not make its way to CPAN, but I'll post it here.

Update: I would also suggest looking at Tricks with DBI especially the section on placeholders.

Simon Flack ($code or die)
$,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
=~y'_"' ';eval"die";print $_,lc substr$@,0,3;

In reply to Re: usertracking by $code or die
in thread usertracking by khippy

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.