Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Problem with sessions. (http://www.go4expert.com/forums/problem-with-sessions-t12451/)

vitali 26Jul2008 05:23

Problem with sessions.
 
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?

pradeep 7Aug2008 17:56

Re: Problem with sessions.
 
Hi Vitali,
Why don't you go and check this thread http://www.go4expert.com/showthread.php?t=1077 while I go through your code.


All times are GMT +5.5. The time now is 11:06.