Cookies: issue with retrieving?
homegrown perl developer usually on linux, but this is on windows box, but not sure that matters....
Can't call method "cookie" on an undefined value at \cgi-bin\article_admin.pl line 11.
error when trying to retrieve cookie value (for a cookie of name 'articles' that i set on a previous page) via CGI in order to test whether user should have access to this page. the relevant code snippet is below. not sure why it would have an undefined value? can anyone help, as i'm undoubtedly just being stupid but am working alone right now and very stuck. thanks.
3 use strict;
5 use CGI;
6 use CGI::Carp qw(fatalsToBrowser);
8 my $query = new CGI;
9 my $cgi;
10 my $cookie_exists ="no";
11 $cookie_exists = $cgi->cookie('articles');
What's the my $cgi for?? (not needed in this example)
and you don't need line 10 but rather....
my $cookie_exists = $query->cookie('articles');
$cookie_exists = 'no' unless ($cookie_exists);
Nedals is right.
To explain a little more just in case you don't see the error.
you created a CGI object as $query. Later on in the code you call the cookie method from $cgi as if it were a CGI object. You would need to call cookie() on $query based on the code you gave us.
thanks folks. all working now, and one little bit more knowledge sinks in...
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)