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;