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

Posted on 2010-04-06
Medium Priority
Last Modified: 2013-12-25

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??


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 );



print header,
"Enter your name: ",textfield('name'),
"Enter your Password: ",textfield('pass'),



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";


 # 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;

Open in new window

Question by:fosiul01
1 Comment

Accepted Solution

fredmc earned 2000 total points
ID: 30028599
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


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question