Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I hope its easy for me to learn how to use this module properly. It sort of scares the heck out of me for some reason :( ~~~~~
First, I have a couple of perl and html files that all require a session token/user from a cookie--- Would it make sense for me to write a separate perl file (lets say authorize.pl) to have all the CGI::Session coding to validate, expire, delete, and logout? That way, each of the perl and html files on my website will use "require authorize.pl" to control the session management, ---that way I don't need all the CGI::Session coding throughout my perl and html files. Then I can just call sub routines from authorize.pl and place a simple "&validate" or "&create"
Thanks
Re: I'm about to Learn how to use CGI::Session
by Joost (Canon) on Jun 11, 2005 at 13:08 UTC
|
That's a good idea. I would recommend you put the code in a real module (see perlmod) instead of a .pl file.
If you're willing to refactor your code, you could also take a look at CGI::Application::Session, which combines CGI::Session and CGI::Application. It makes sessions even easier to use and provides hooks for authentication etc.
| [reply] |
Re: I'm about to Learn how to use CGI::Session
by stonecolddevin (Parson) on Jun 11, 2005 at 10:30 UTC
|
That would be a brilliant idea. As you get farther along and into bigger projects, you'll find organization and classification are CRITICAL to your code's success.
It's pretty much standard to put frequently used functions in a library and call them as needed.
| [reply] |
Re: I'm about to Learn how to use CGI::Session
by mda2 (Hermit) on Jun 13, 2005 at 02:21 UTC
|
Itīs a good pratice, but if you have a big site, use of CGI to autenticate all page views can are a bad idea. CGI have costs with load, parse, compile and run.
Eval use of <a href="http://perl.apache.org>modperl to do it. See a good book Writing Apache Modules with Perl and C (See the code samples).
On modperl environment you have Apache::Session like CGI::Session...
Compare features (and dates):
- Apache::Session
- CGI::Session
| [reply] |
|