does not support cookie() and param() methods : why ??

Hi

if you look at myindex.pl.

when there is not any session in /tmp directory, now if i try to open myindex.pl

its showing : you have not logged in.

but some times, if i refresh the page couple of times, , it is giving me bellow error

Error :
 -e: new(): failed: query object HASH(0xa850044) does not support cookie() and param() methods: Can't call method "cookie" on unblessed reference at /usr/lib/perl5/site_perl/5.8.8/CGI/Session.pm line 707.\n


can any one tell me why ?

more explanation:

when i am going to myindex.pl file directly(by passing the mylogin.pl) it should show : you have not logged in. which its showing.

but if i refresh the page couple of times, it will show that error, then again if i refresh, its working fine

so why its showing that error ???
is there any code related problem??

mylogin.pl

======================
#!/usr/bin/perl
use strict;

use CGI qw/:standard/;
use CGI::Session;
my $data =  new CGI;

my $user = $data->param('name');
my $pwd  = $data->param('pass');

if($user eq "fosiul"  and $pwd eq "demo")
{

 my $session = new CGI::Session("driver:File", undef, {Directory=>'/tmp'});
# getting the effective session id:
    my $CGISESSID = $session->id();

 # storing data in the session
    $session->param('f_name', $user);
    $session->param('f_pass', $pwd);
my $cookie = $data->cookie(CGISESSID => $session->id);
    print $data->header( -cookie=>$cookie );



$session->header(-location=>'myindex.pl');

exit;
}

else
{
print header,
start_html('Hello'),
start_form(-method=>'POST',-action=>"/cgi-perl/mylogin.pl"),
"Enter your name: ",textfield('name'),
"Enter your Password: ",textfield('pass'),
submit,
end_form,
hr,


}
========================
myindex.pl

#####################

#!/usr/bin/perl
use strict;
use CGI qw/:standard/;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use CGI::Session;

my $cgi = CGI->new;

#Bellow line will try to open existing session if not then will create
# a new session


my $session = CGI::Session->load() or die CGI::Session->errstr;


if ($session->is_empty)

 {
      print header;
      print "You have not logged in";

 }

else
{
 # retrieving data
    my $f_name = $session->param('f_name');
   my $f_pass = $session->param('f_pass');
print header;
print start_html('Hello');
print $f_name;

print h1('your password is successfull');
print end_html;
exit;
}

Open in new window

LVL 29
fosiul01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Frederick McIntyreProgrammerCommented:
I've not used CGI::Session, so this may be off track. It would appear to me that in myindex.pl you need to retrieve the session id from the cookie and use it in the load(). You might try replacing line 64 with this:
my $CGISESSID = $cgi->cookie('CGISESSID');
my $session = CGI::Session->load($CGISESSID) or die CGI::Session->errstr;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.