1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Problem with sessions.

Discussion in 'Perl' started by vitali, Jul 26, 2008.

  1. vitali

    vitali New Member

    Hello.

    I trying to create a login script, but i keep having weird problem with sessions.

    Here is the chunk of code from login.pm, that creates session variables and redirects to the next page if login is valid:
    Code:
    #!/usr/bin/perl -wT
    
    use CGI qw/:standard/;
    use strict;
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
    use DBI;
    use CGI::Session;
    
    
    my $cgi = new CGI;
    my $session = new CGI::Session(undef,$cgi,{Directory=>'/tmp'});
    my $cookie = $cgi->cookie(CGISESSID => $session->id);
    
    my $id;
    my $login;
    my ($status, $full_name) = &login;
    
    #------------------------------------------------------------------
    #------------------------------------------------------------------
    if (param('sign_in')){
    	if ($status eq "allow"){
    		$session->param('user_name', $full_name);
    		$session->param('user_status', $status);
    		print redirect('./order_list.dhtml');
    		#print header;
    		#print "You have loged in.",br;
    		#my $user_status = $session->param("user_status");
    		#print $full_name,br,$user_status;
    	} else {
    		print $cgi->header(-cookie=>$cookie);
    		print start_html;
    		print "Login Failed",br;
    		&login_form;
    		print end_html;
    	}
    } else {
    	print $cgi->header(-coockie=>$cookie);
    	print start_html;
    	&login_form;
    	print end_html;
    }
    
    For some odd reason it will only let me through if I'll fail login once.

    Here is the chunk of code from the page that I'm suppose to get redirected to:
    Code:
    #!/usr/bin/perl -wT
    
    use CGI qw(:standard);
    use strict;
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
    use DBI;
    use CGI::Session ('-ip_match');
    
    my $cgi = new CGI;
    #my $session = new CGI::Session(undef,$cgi,{Directory=>'/tmp'});
    my $session = CGI::Session->load();
    my $user_status = $session->param("user_status");
    my $user_name = $session->param("user_name");
    
    
    if ($user_status eq "allow"){
    print $cgi->header(-cookie=>cookie);
    print start_html("Order list");
    print $user_status;
    print $user_name;
    print end_html;
    } else {
    print redirect('./login.dhtml');
    }
    
    Any thoughts?
     
  2. pradeep

    pradeep Team Leader

Share This Page