Hi

In my script i am using template toolkit. I am trying to set the
cookie in my browser but all that it does is  it prints the following
output on my broswer :

Set-Cookie: CGISESSID=f032fc8982a1ae022c4f51baa3bc4143; path=/ Date:
Wed, 04 May 2011 13:07:40 GMT Content-Type: text/html;
charset=ISO-8859-1

here is my script , how do is set  cookie
=========================

#!/usr/bin/perl
use strict ;
use warnings ;
use Template;
use Data::Dumper;
use CGI::Session;
use CGI;

print "Content-type: text/html\n\n";

 my $cgi = new CGI;
 my $session = new CGI::Session(undef, $cgi, {Directory=>'/tmp'});


my $tt = Template->new( INCLUDE_PATH => "/var/www/html/template" ) ||
die "template process failed:$!";

my %tag;

            $session->clear();
            $session->expire('+2h');


my $evalue =  init($cgi, $session);

if ( $evalue == 3 ) {
 my  $cookie = $cgi->cookie(CGISESSID => $session->id);
    print $cgi->header( -cookie=>$cookie );
      deploy_page();

}


    unless ( $session->param("~logged-in") ) {
        login_page();
        $session->delete();
        exit(0);

    }


sub init {
        my ($cgi,$session) = @_; # receive two args

        if ( $session->param("~logged-in") ) {
            return 3 ;  # if logged in, don't bother going further
        }



        my $lg_name = $cgi->param("lg_name") or "dfdsfsd";
        my $lg_psswd = $cgi->param("lg_password") or "dsfdsfsd";

        # if we came this far, user did submit the login form
        # so let's try to load his/her profile if name/psswds match
        if ( my $profile = _load_profile($lg_name, $lg_psswd) ) {

            $session->param("~profile", $profile);
            $session->param("~logged-in", 1);
            $session->clear(["~login-trials"]);

          return 3;
        }

    }


 sub _load_profile {
        my ($lg_name, $lg_psswd) = @_;
        local $/ = "\n";
        unless (sysopen(PROFILES, "profiles.txt", O_RDONLY) ) {
            die "Couldnt open profiles.txt: $!";
        }
        while ( <PROFILES> ) {
            /^(\n|#)/ and next;
            chomp;
            my ($n, $p, $e) = split (/\s+/,$_) ;
            if ( ($n eq $lg_name) && ($p eq $lg_psswd) ) {
                my $p_mask = "x" . length($p);

                return {username=>$n, password=>$p_mask, email=>$e};
            }
        }
        close(PROFILES);

        return undef;
    }


sub deploy_page {

$tt->process("form/form.html") || die $tt->error();
}

sub login_page {

$tt->process("login.tmpl",\%tag) || die $tt->error();
}
==============================================

thanks for all the help !!

-- 
Regards
Agnello D'souza

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to