[Israel.pm] CGI::Session

ik idokan at gmail.com
Fri Mar 7 09:58:30 EET 2008


On Fri, Mar 7, 2008 at 9:54 AM, Gabor Szabo <szabgab at gmail.com> wrote:
>
> On Fri, Feb 29, 2008 at 11:25 AM, ik <idokan at gmail.com> wrote:
>  > Hello,
>  >
>  >  The use of a session is to save data like in cookie, where the only
>  >  difference is that it is stored on the server side rather then the
>  >  client side (that only stores the identifier of the session as a
>  >  cookie).
>  >
>  >  So your authentication should look like so:
>  >
>  >  if ($session['user'] ne '' and $session['authenticated'] eq 1)
>  >  {
>  >   user already authenticated
>  >  }
>  >  else
>  >  {
>  >    do a regular authentication process
>  >
>  >    $session['user']              = $user;
>  >    $sesson['authenticated'] = 1;
>  >    ...
>  >  }
>  >
>  >  One very important rule for CGI::Sessions, you must flush the data
>  >  before you finish your work or you will have strange errors and
>  >  problems.
>  >
>  >  Ido
>  >
>  >
>  >
>  >  On Fri, Feb 29, 2008 at 11:11 AM, Shmuel Fomberg <semuelf at 012.net.il> wrote:
>  >  > Hello All.
>  >  >
>  >  >  I'm trying to write a new web site, and was reading about CGI::Application
>  >  >  and CGI::Session.
>  >  >  I understand how the CGI::Session use some storage (either file of a
>  >  >  simplified database table) to store session information, and a cookie to
>  >  >  connect the user to that session. But how do I authenticate the user? Where
>  >  >  in the loop I verify user name/password, and say 'I know this user, this is
>  >  >  his data', for the Session object to keep?
>  >  >
>  >  >  Thanks,
>  >  >  Shmuel.
>  >  >
>
>  While to some of you that might be obvious but let me make sure
>  that anyone reading our archives will also understand that the
>  example above is actually in PHP.

You are correct. That what happens when you use too much PHP and not
enough Perl :(

>
>  In Perl a hash is not the same as an array and thus the
>  variable needs {} around the key.
>  The example is better written in Perl like this:
>
>
>  if ($session{user} and $session{authenticated}) {
>    # user already authenticated
>
> }  else {
>    # do a regular authentication process
>    $session{user}              = $user;
>    $sesson{authenticated} = 1;
>    ...
>  }
>
>  Gabor
>
>
>
>  --
>  Gabor Szabo
>  http://www.szabgab.com/
>  Perl Training in Israel  http://www.pti.co.il/
>  Profile: http://www.linkedin.com/in/szabgab
>
>
> _______________________________________________
>  Perl mailing list
>  Perl at perl.org.il
>  http://perl.org.il/mailman/listinfo/perl
>


Ido
-- 
http://ik.homelinux.org/


More information about the Perl mailing list