Problem with sessions.

vitali's Avatar, Join Date: Jul 2008
Newbie 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?
pradeep's Avatar, Join Date: Apr 2005
Team Leader
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.