how session tracking is done in perl?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poolboi
    New Member
    • Jan 2008
    • 170

    #1

    how session tracking is done in perl?

    hey guys,

    i've done most of my web app. for searching almost done
    but then i got a small little problem with logging in
    i need to know how session tracking is done in perl
    if not my log in page would truely be redundant
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by poolboi
    hey guys,

    i've done most of my web app. for searching almost done
    but then i got a small little problem with logging in
    i need to know how session tracking is done in perl
    if not my log in page would truely be redundant
    Well, to manage the session you could use the CGI::Session Perl module.

    Regards,

    Jeff

    Comment

    • poolboi
      New Member
      • Jan 2008
      • 170

      #3
      thanks..
      i've actually found a workable code

      right this code is for logging in
      [CODE=perl]
      #!/perl/bin/perl

      use CGI;
      use CGI::Session (' ip_match ');
      use CGI::Carp qw/fatalsToBrowser warningsToBrows er/;

      $q = new CGI;

      $usr = $q->param('usr') ;
      $pwd = $q->param('pwd') ;

      if ($usr ne '')
      {
      if($usr eq "demo" and $pwd eq "demo")
      {
      $session = new CGI::Session();
      print $session->header(-location=>'inde x.pl');
      }
      else
      {
      print $q->header(-type=>"text/html",-location=>"logi n.pl");
      }
      }
      elsif($q->param('action' ) eq 'logout')
      {
      $session = CGI::Session->load() or die CGI::Session->errstr;
      $session->delete();
      print $session->header(-location=>'logi n.pl');
      }
      else
      {
      print $q->header;
      print <<HTML;
      <form method="post">
      Username: <input type="text" name="usr">

      Password: <input type="password" name="pwd">


      <input type="submit">
      [/CODE]

      and the other is for validating at the top of each cgi script
      [CODE=perl]
      #!/perl/bin/perl

      # index.pl
      use CGI;
      use CGI::Carp qw/fatalsToBrowser warningsToBrows er/;
      use CGI::Session ( '-ip_match' );

      $session = CGI::Session->load();
      $q = new CGI;

      if($session->is_expired)
      {
      print $q->header(-cache_control=> "no-cache, no-store, must-revalidate");
      print "Your has session expired. Please login again.";
      print "<br/><a href='text.pl>L ogin</a>";
      }
      elsif($session->is_empty)
      {
      print $q->header(-cache_control=> "no-cache, no-store, must-revalidate");
      print "You have not logged in";
      }
      else
      {
      print $q->header(-cache_control=> "no-cache, no-store, must-revalidate");
      print "<h2>Welcom e";
      print "<a href='test.pl?a ction=logout'>L ogout";
      }
      [/CODE]

      i'm just wondering
      i i were to write the validation code at the top each time..
      it's so troublesome
      is there any way i can call this script or anything
      so that i dun have to always repeat the whole chunk of code?

      Comment

      Working...